Skip to content

Commit fe1e905

Browse files
committed
feat(leetcode): add No.3033
1 parent 0cb7395 commit fe1e905

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

3033.Modify-the-Matrix.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// https://leetcode.com/problems/modify-the-matrix/description/
2+
// algorithms
3+
// Easy (67.1%)
4+
// Total Accepted: 28.3K
5+
// Total Submissions: 42.2K
6+
7+
8+
class Solution {
9+
10+
public int[][] modifiedMatrix(int[][] matrix) {
11+
int m = matrix.length;
12+
int n = matrix[0].length;
13+
14+
int[][] res = new int[m][n];
15+
for (int i = 0; i < n; i++) {
16+
List<Integer> idxList = new LinkedList<>();
17+
int maxValue = Integer.MIN_VALUE;
18+
for (int j = 0; j < m; j++) {
19+
if (matrix[j][i] == -1) {
20+
idxList.add(j);
21+
} else {
22+
res[j][i] = matrix[j][i];
23+
maxValue = Math.max(maxValue, matrix[j][i]);
24+
}
25+
}
26+
27+
for (int idx : idxList) {
28+
res[idx][i] = maxValue;
29+
}
30+
}
31+
32+
return res;
33+
}
34+
35+
}

0 commit comments

Comments
 (0)