일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 30. Substring with Concatenation of All Words
- t1
- 파이썬
- DWG
- 시바견
- data science
- Regular Expression
- 컴퓨터의 구조
- Python
- iterator
- concurrency
- Class
- 운영체제
- shiba
- 715. Range Module
- 315. Count of Smaller Numbers After Self
- Generator
- 43. Multiply Strings
- Substring with Concatenation of All Words
- Python Implementation
- Decorator
- Protocol
- kaggle
- 밴픽
- LeetCode
- 109. Convert Sorted List to Binary Search Tree
- Convert Sorted List to Binary Search Tree
- 프로그래머스
- Python Code
- attribute
Archives
- Today
- Total
Scribbling
LeetCode: 73. Set Matrix Zeroes 본문
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
m, n = len(matrix), len(matrix[0])
for y in range(m):
for x in range(n):
if matrix[y][x] == 0:
self.inspect_row(matrix, y, x)
self.inspect_column(matrix, y, x)
elif matrix[y][x] == 'row inspected zero':
self.inspect_column(matrix, y, x)
elif matrix[y][x] == 'column inspected zero':
self.inspect_row(matrix, y, x)
else:
continue
for y in range(m):
for x in range(n):
if type(matrix[y][x]) != int:
matrix[y][x] = 0
def inspect_row(self, matrix, y, x):
for i in range(len(matrix[0])):
cur = matrix[y][i]
if cur == 0:
matrix[y][i] = 'row inspected zero'
elif cur == 'row inspected zero':
continue
elif cur == 'column inspected zero':
matrix[y][i] = 'both inspected zero'
elif cur == 'both inspected zero':
continue
else:
matrix[y][i] = 'to be zero'
def inspect_column(self, matrix, y, x):
for i in range(len(matrix)):
cur = matrix[i][x]
if cur == 0:
matrix[i][x] = 'column inspected zero'
elif cur == 'row inspected zero':
matrix[i][x] = 'both inspected zero'
elif cur == 'column inspected zero':
continue
elif cur == 'both inspected zero':
continue
else:
matrix[i][x] = 'to be zero'
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 75. Sort Colors (0) | 2021.09.28 |
---|---|
LeetCode: 74. Search a 2D Matrix (0) | 2021.09.28 |
LeetCode: 72. Edit Distance (0) | 2021.09.26 |
LeetCode: 71. Simplify Path (0) | 2021.09.26 |
LeetCode: 69. Sqrt(x) (0) | 2021.09.26 |