phatboislym

Untitled

Dec 14th, 2023
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | Source Code | 0 0
  1. class Solution:
  2.     def onesMinusZeros(self, grid: List[List[int]]) -> List[List[int]]:
  3.         def getColumn(column: int) -> list:
  4.             return [row[column] for row in grid]
  5.        
  6.         rows: int = len(grid)
  7.         cols: int = len(grid[0])
  8.         onesCol: list = []
  9.         zerosCol: list = []
  10.         onesRow: list = []
  11.         zerosRow: list = []
  12.  
  13.         for i in range(cols):
  14.             col: list = getColumn(i)
  15.             onesCol.append(col.count(1))
  16.             zerosCol.append(col.count(0))
  17.  
  18.         for i in range(rows):
  19.             onesRow.append(grid[i].count(1))
  20.             zerosRow.append(grid[i].count(0))
  21.  
  22.         diff: list = [[0] * cols for i in range(rows)]
  23.  
  24.         for i in range(rows):
  25.  
  26.             for j in range(cols):
  27.  
  28.                 diff[i][j] = onesRow[i] + onesCol[j] - zerosRow[i] - zerosCol[j]
  29.  
  30.         return diff
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment