题解 | #棋子翻转#
棋子翻转
https://www.nowcoder.com/practice/a8c89dc768c84ec29cbf9ca065e3f6b4
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param A int整型二维数组
* @param f int整型二维数组
* @return int整型二维数组
*/
function flipChess( A , f ) {
// write code here
let m = A.length; // 行
let n = A[0].length; // 列
// 遍历每一个操作
for(let i=0; i<f.length; i++){
let x=f[i][0]-1, y=f[i][1]-1; // 转换成真实的坐标
// 边界判断
if(x>0) A[x-1][y] = 1-A[x-1][y];
if(y>0) A[x][y-1] = 1-A[x][y-1];
if(x<m-1) A[x+1][y] = 1-A[x+1][y];
if(y<n-1) A[x][y+1] = 1-A[x][y+1];
}
return A
}
module.exports = {
flipChess : flipChess
};
