题解 | #棋子翻转#

棋子翻转

https://www.nowcoder.com/practice/a8c89dc768c84ec29cbf9ca065e3f6b4

按照题意模拟即可
public class Solution {
    public int[][] flipChess (int[][] A, int[][] f) {
        int[] dx = {-1,0,1,0},dy = {0,1,0,-1};
        int n = A.length;
        for(int[] arr : f){
            int x = arr[0]-1,y = arr[1]-1;
            for(int i = 0; i < n; i++){
                int cx = x + dx[i],cy = y + dy[i];
                if(cx < 0 || cx >= n || cy < 0 || cy >= n){
                    continue;
                }
                A[cx][cy] = A[cx][cy]==1?0:1;
            }
        }
        return A;
    }
}


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务