Leetcode 2268 Solution

This article provides solution to leetcode question 2268 (remove-all-ones-with-row-and-column-flips)

https://leetcode.com/problems/remove-all-ones-with-row-and-column-flips

Solution

class Solution: def removeOnes(self, grid: List[List[int]]) -> bool: m = len(grid) n = len(grid[0])
def flip(row): if row[0] == 1: return row else: for i in range(len(row)): row[i] = 1 - row[i] return row
target = flip(grid[0])
for i in range(1, m): if target != flip(grid[i]): return False
return True