mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-14 07:47:08 +00:00
Time: 0 ms (100%), Space: 18.6 MB (17.59%) - LeetHub
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user