Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 1.28 KB

_2482. Difference Between Ones and Zeros in Row and Column.md

File metadata and controls

48 lines (34 loc) · 1.28 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 07, 2024

Last updated : July 01, 2024


Related Topics : Array, Matrix, Simulation

Acceptance Rate : 84.461 %


Solutions

Python

class Solution:
    def onesMinusZeros(self, grid: List[List[int]]) -> List[List[int]]:
        rowCounts = [0] * len(grid)
        colCounts = [0] * len(grid[0])

        for i in range(len(grid)) :
            rowCounts[i] = sum(grid[i])

        for i in range(len(grid[0])) :
            for j in range(len(grid)) :
                colCounts[i] += grid[j][i]
        
        output = []
        for i in range(len(grid)) :
            output.append([])

        for i in range(len(grid)) :
            for j in range(len(grid[0])) :
                output[i].append(2 * (colCounts[j] + rowCounts[i]) - len(grid) - len(grid[0]))
        return output