简单模拟,唯一要考虑的就是越界问题
class Solution {
public:
vector<vector<int> > flipChess(vector<vector<int> >& A, vector<vector<int> >& f) {
// write code here
int n=f.size();
for(int i=0;i<n;i++){
int x=f[i][0]-1,y=f[i][1]-1;
if(x-1>=0){ //判断越界情况;
A[x-1][y]=A[x-1][y]==0?1:0; //利用三目运算符进行翻转;
}
if(x+1<4){
A[x+1][y]=A[x+1][y]==0?1:0;
}
if(y-1>=0){
A[x][y-1]=A[x][y-1]==0?1:0;
}
if(y+1<4){
A[x][y+1]=A[x][y+1]==0?1:0;
}
}
return A;
}
};



京公网安备 11010502036488号