일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 컴퓨터의 구조
- Protocol
- iterator
- 43. Multiply Strings
- t1
- 315. Count of Smaller Numbers After Self
- Python Code
- Convert Sorted List to Binary Search Tree
- Generator
- Class
- DWG
- LeetCode
- Regular Expression
- 운영체제
- Substring with Concatenation of All Words
- shiba
- 밴픽
- 30. Substring with Concatenation of All Words
- 시바견
- 파이썬
- data science
- 715. Range Module
- Decorator
- 프로그래머스
- Python Implementation
- concurrency
- 109. Convert Sorted List to Binary Search Tree
- attribute
- Python
- kaggle
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 |