题解 | #棋子翻转# Python3

棋子翻转

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

class Solution:
    def flipChess(self , A: List[List[int]], f: List[List[int]]) -> List[List[int]]:
        # write code here
        M=len(A)
        for pos in f:
            px,py=pos[0]-1,pos[1]-1
            for x,y in [(px-1,py),(px+1,py),(px,py-1),(px,py+1)]:
                if 0<=x<M and 0<=y<M:
                    A[x][y]=1-A[x][y]
        return A

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务