3033. 修改矩阵
题目来源:
leetcode题目:3033. 修改矩阵 - 力扣(LeetCode)
解题思路:
获取每列的最大值后将-1替换即可。
解题代码:
#python3
class Solution:def getMaxRow(matrix:List[List[int]])->List[int]:res=[]for i in range(0,len(matrix[0])):maxNum=matrix[0][i]for j in range(0,len(matrix)):maxNum=max(maxNum,matrix[j][i])res.append(maxNum)return resdef modifiedMatrix(self, matrix: List[List[int]]) -> List[List[int]]:res=[]maxRow=Solution.getMaxRow(matrix)for i in range(0,len(matrix)):res.append([])for j in range(0,len(matrix[i])):if matrix[i][j]!=-1:res[i].append(matrix[i][j])else:res[i].append(maxRow[j])return res
总结:
官方题解也是遍历。