forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1329.java
More file actions
23 lines (23 loc) · 736 Bytes
/
1329.java
File metadata and controls
23 lines (23 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public int[][] diagonalSort(int[][] mat) {
int m = mat.length, n = mat[0].length;
int[] t = new int[Math.min(m, n)];
for (int i = 0; i < m; i++) {
int k = Math.min(m - i, n);
for (int j = 0; j < k; j++) {
t[j] = mat[i + j][j];
}
Arrays.sort(t, 0, k);
for (int j = 0; j <k; ++j) mat[i + j][j] = t[j];
}
for (int i = 1; i < n; i++) {
int k = Math.min(m, n - i);
for (int j = 0; j < k; j++) {
t[j] = mat[j][i + j];
}
Arrays.sort(t, 0, k);
for (int j = 0; j < k; j++) mat[j][i + j] = t[j];
}
return mat;
}
}