파비의 매일매일 공부기록

2023.12.16 Today's Challenge 본문

Problem Solving/LeetCode

2023.12.16 Today's Challenge

fabichoi 2023. 12. 16. 23:45

https://leetcode.com/problems/difference-between-ones-and-zeros-in-row-and-column/?envType=daily-question&envId=2023-12-14

 

Difference Between Ones and Zeros in Row and Column - LeetCode

Can you solve this real interview question? Difference Between Ones and Zeros in Row and Column - You are given a 0-indexed m x n binary matrix grid. A 0-indexed m x n difference matrix diff is created with the following procedure: * Let the number of ones

leetcode.com

문제가 이해가 잘 안되서 일단 패스..!

class Solution:
    def onesMinusZeros(self, grid: List[List[int]]) -> List[List[int]]:
        m, n = len(grid), len(grid[0])
        row_ones = [0] * m
        col_ones = [0] * n

        for i in range(m):
            for j in range(n):
                row_ones[i] += grid[i][j]
                col_ones[j] += grid[i][j]
        
        for i in range(m):
            for j in range(n):
                grid[i][j] = 2 * (row_ones[i] + col_ones[j]) - m - n
        
        return grid
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.12.18 Today's Challenge  (0) 2023.12.18
2023.12.17 Today's Challenge  (0) 2023.12.17
2023.12.15 Today's Challenge  (0) 2023.12.15
2023.12.14 Today's Challenge  (0) 2023.12.14
2023.12.13 Today's Challenge  (0) 2023.12.13
Comments