[LeetCode][Python3] 73. Set Matrix Zeroes
2019. 3. 27. 01:39 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/set-matrix-zeroes/
My Solution :
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
Y, X = len(matrix), len(matrix[0])
y0 = True if 0 in matrix[0] else False
x0 = True if 0 in [row[0] for row in matrix] else False
for y in range(1, Y):
for x in range(1, X):
if matrix[y][x] == 0:
matrix[y][0] = 0
matrix[0][x] = 0
for y in range(1, Y):
for x in range(1, X):
if 0 in (matrix[y][0], matrix[0][x]):
matrix[y][x] = 0
if y0:
for x in range(X):
matrix[0][x] = 0
if x0:
for y in range(Y):
matrix[y][0] = 0
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 208. Implement Trie (Prefix Tree) (1) | 2019.03.30 |
---|---|
[LeetCode][Python3] 239. Sliding Window Maximum (0) | 2019.03.29 |
[LeetCode][Python3] 315. Count of Smaller Numbers After Self (0) | 2019.03.28 |
[LeetCode][Python3] 395. Longest Substring with At Least K Repeating Characters (0) | 2019.03.28 |
[LeetCode][Python3] 329. Longest Increasing Path in a Matrix (0) | 2019.03.27 |
[LeetCode][Python3] 264. Ugly Number II (0) | 2019.03.26 |
[LeetCode][Python3] 334. Increasing Triplet Subsequence (0) | 2019.03.25 |
[LeetCode][Python3] 297. Serialize and Deserialize Binary Tree (0) | 2019.03.25 |
최근에 달린 댓글 최근에 달린 댓글