题解 | #棋子翻转#

棋子翻转

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

#emmmmmm,节俭运算,取非运算,偶数次可以省去
class Solution:
    def flipChess(self, A: List[List[int]], f: List[List[int]]) -> List[List[int]]:
        # write code here
        points = []
        for point in f:
            point_l = [point[0] - 1, point[1]]
            point_r = [point[0] + 1, point[1]]
            point_t = [point[0], point[1] - 1]
            point_b = [point[0], point[1] + 1]

            if point_l not in points:
                points.append(point_l)
            else:
                points.remove(point_l)

            if point_r not in points:
                points.append(point_r)
            else:
                points.remove(point_r)

            if point_t not in points:
                points.append(point_t)
            else:
                points.remove(point_t)

            if point_b not in points:
                points.append(point_b)
            else:
                points.remove(point_b)

        for point in points:
            h = len(A)
            w = len(A[0])
            if point[0]>0 and point[0]<=h and point[1]>0 and point[1]<=w:
                A[point[0]-1][point[1]-1] = int(not A[point[0]-1][point[1]-1])

        return A

#我的实习求职记录#
全部评论

相关推荐

Java抽象带篮子:难蚌,点进图片上面就是我的大头😆
点赞 评论 收藏
分享
11-18 15:57
门头沟学院 Java
最终归宿是测开:这个重邮的大佬在重邮很有名的,他就喜欢打92的脸,越有人质疑他,他越觉得爽😂
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务