题解 | #棋子翻转#

棋子翻转

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

class Solution:
    def flipChess(self , A: List[List[int]], f: List[List[int]]) -> List[List[int]]:
        # 把上下左右 0 --》1, 1--》0
        dirs = [(0,1),(0,-1),(1,0),(-1,0)]
        rows,cols = len(A), len(A[0])
        for row,col in f:
            for i,j in dirs:
                x = row + i -1
                y = col + j -1
                if 0 <= x< rows and 0<= y < cols:
                    A[x][y] ^= 1
        return A 

全部评论
这里^符号是什么意思呢
点赞 回复 分享
发布于 2022-09-09 15:14 吉林

相关推荐

点赞 评论 收藏
分享
醉蟀:你是我今年见过的最美牛客女孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务