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해서 사용합니다.
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2784. Check if Array is Good (0) | 2024.02.14 |
---|---|
leetcode 3024. Type of Triangle (0) | 2024.02.13 |
leetcode 2357. Make Array Zero by Subtracting Equal Amounts (1) | 2024.02.09 |
leetcode 2586. Count the Number of Vowel Strings in Range (0) | 2024.02.09 |
백준 Not A + B (0) | 2024.02.09 |
댓글