Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def onesMinusZeros(self, grid: List[List[int]]) -> List[List[int]]:
- def getColumn(column: int) -> list:
- return [row[column] for row in grid]
- rows: int = len(grid)
- cols: int = len(grid[0])
- onesCol: list = []
- zerosCol: list = []
- onesRow: list = []
- zerosRow: list = []
- for i in range(cols):
- col: list = getColumn(i)
- onesCol.append(col.count(1))
- zerosCol.append(col.count(0))
- for i in range(rows):
- onesRow.append(grid[i].count(1))
- zerosRow.append(grid[i].count(0))
- diff: list = [[0] * cols for i in range(rows)]
- for i in range(rows):
- for j in range(cols):
- diff[i][j] = onesRow[i] + onesCol[j] - zerosRow[i] - zerosCol[j]
- return diff
Advertisement
Add Comment
Please, Sign In to add comment