mirror of
https://github.com/aykhans/leet-code-problems.git
synced 2025-04-21 05:03:33 +00:00
Added set_zeroes
This commit is contained in:
parent
30ce7fdc37
commit
c8082eafc0
@ -103,3 +103,26 @@ class AcceptedMedium:
|
|||||||
if len(set(r)) < len(r): return False
|
if len(set(r)) < len(r): return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def set_zeroes(self, matrix: List[List[int]]) -> None:
|
||||||
|
# sourcery skip: use-itertools-product
|
||||||
|
"""
|
||||||
|
Link: https://leetcode.com/problems/set-matrix-zeroes/description/
|
||||||
|
Runtime: 5780 ms
|
||||||
|
"""
|
||||||
|
column_len = len(matrix)
|
||||||
|
row_len = len(matrix[0])
|
||||||
|
dont_replace = []
|
||||||
|
|
||||||
|
for c in range(column_len):
|
||||||
|
for r in range(row_len):
|
||||||
|
if matrix[c][r] == 0 and [c, r] not in dont_replace:
|
||||||
|
print(c, r)
|
||||||
|
for i in range(column_len):
|
||||||
|
if matrix[i][r] != 0:
|
||||||
|
matrix[i][r] = 0
|
||||||
|
dont_replace.append([i, r])
|
||||||
|
for i in range(row_len):
|
||||||
|
if matrix[c][i] != 0:
|
||||||
|
matrix[c][i] = 0
|
||||||
|
dont_replace.append([c, i])
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.10.4"
|
"version": "3.10.6"
|
||||||
},
|
},
|
||||||
"orig_nbformat": 4,
|
"orig_nbformat": 4,
|
||||||
"vscode": {
|
"vscode": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user