-
[LeetCode] HashTable/ 73. Set Matrix Zeroes알고리즘 2022. 6. 12. 22:28
from collections import defaultdict class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: """ Do not return anything, modify matrix in-place instead. """ n = len(matrix) m = len(matrix[0]) rows = defaultdict(int) cols = defaultdict(int) for i in range(n): for j in range(m): if (matrix[i][j] == 0): rows[i] = 1 cols[j] = 1 for i in range(n): for j in range(m): if (rows[i] == 1 or cols[j] == 1): matrix[i][j] = 0 return matrix
'알고리즘' 카테고리의 다른 글
Manacher's Algorithm [가장 긴 펠렌드롬 찾기] (0) 2022.06.20 [LeetCode] DP / Unique-paths (0) 2022.06.14 [Leetcode] 플로이드와샬 / 1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance (0) 2022.06.11 [LeetCode] 1905. Count Sub Islands (0) 2022.06.02 [LeetCode] 1020. Number of Enclaves (0) 2022.05.31