python-algorithm
leetcode 3033. Modify the Matrix
무적김두칠
2024. 2. 13. 16:45
https://leetcode.com/problems/modify-the-matrix/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
class Solution:
def modifiedMatrix(self, matrix: List[List[int]]) -> List[List[int]]:
m = len(matrix)
n = len(matrix[0])
for col in range(n):
tmp_max = matrix[0][col]
change_flag = False
change_idx = []
for row in range(m):
tmp_max = max(tmp_max, matrix[row][col])
if matrix[row][col] == -1:
change_idx.append(row)
change_flag = True
if change_flag:
for i in change_idx:
matrix[i][col] = tmp_max
return matrix
|
cs |
이차원배열에 대한 문제고 그렇게 어렵진않은데
-1이 나오는 경우가 한 col에 여러개가 있는 경우를 놓쳐서 수정하고 리스트에 append해서 사용합니다.
반응형