#3033
Modify the Matrix
pupil · 300 · lc easy +20 · verified · 69% accepted · 153 likes · top 76%
Description
Given a 0-indexed m x n integer matrix matrix, produce a new matrix answer equal to matrix, then replace every -1 with the column maximum.
Return answer.
Example 1:
Input: matrix = [[1,2,-1],[4,-1,6],[7,8,9]]
Output: [[1,2,9],[4,8,6],[7,8,9]]
Explanation: The diagram above shows the elements that are changed (in blue).
- We replace the value in the cell [1][1] with the maximum value in the column 1, that is 8.
- We replace the value in the cell [0][2] with the maximum value in the column 2, that is 9.
Example 2:
Input: matrix = [[3,-1],[5,2]]
Output: [[3,2],[5,2]]
Explanation: The diagram above shows the elements that are changed (in blue).
Code
1
2
3