2500. Delete Greatest Value in Each Row

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public int deleteGreatestValue(int[][] grid) {
int m = grid.length, n = grid[0].length;

for (int[] row : grid) {
Arrays.sort(row);
}

int res = 0;
for (int j = n - 1; j >= 0; j--) {
int maxValue = 0;
for (int i = 0; i < m; i++) {
maxValue = Math.max(maxValue, grid[i][j]);
}
res += maxValue;
}

return res;
}
}

References

2500. Delete Greatest Value in Each Row