Time: 0 ms (100%), Space: 18.6 MB (17.59%) - LeetHub

This commit is contained in:
Deven
2025-11-26 14:24:59 -05:00
parent f6089b1e84
commit 3399d5f921
@@ -3,18 +3,22 @@ class Solution:
"""
Do not return anything, modify matrix in-place instead.
"""
# Total complexities:
# O(mn) time
# O(m+n) space
# O(m+n) space
rowsToZero = set()
colsToZero = set()
# Find all zeros
# Find all zeros - O(mn)
for i in range(len(matrix)):
for j in range(len(matrix[i])):
if matrix[i][j] == 0:
rowsToZero.add(i)
colsToZero.add(j)
# Zero rows and cols as needed
# Zero rows and cols as needed - O(mn)
for i in range(len(matrix)):
for j in range(len(matrix[i])):
if i in rowsToZero or j in colsToZero: