题解 | #棋子翻转#
棋子翻转
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#我的实习求职记录#