File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments