-
Notifications
You must be signed in to change notification settings - Fork 0
/
m2679.java
31 lines (27 loc) · 946 Bytes
/
m2679.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public int matrixSum(int[][] nums) {
int sum = 0;
for (int i = 0; i < Math.max(nums[0].length, nums.length); i++) {
int[] temp = new int[nums.length];
// PriorityQueue<Integer> pq = new PriorityQueue<>(nums.length, null);
for (int j = 0; j < nums.length; j++) {
int maxIndex = 0;
for (int k = 0; k < nums[0].length; k++) {
if (nums[j][k] > nums[j][maxIndex]) {
maxIndex = k;
}
}
// pq.add(nums[j][maxIndex]);
temp[j] = nums[j][maxIndex];
nums[j][maxIndex] = 0;
}
// sum += pq.poll();
int max = 0;
for (int j = 0; j < temp.length; j++) {
max = Math.max(max, temp[j]);
}
sum += max;
}
return sum;
}
}