forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1424.java
More file actions
21 lines (20 loc) · 651 Bytes
/
1424.java
File metadata and controls
21 lines (20 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public int[] findDiagonalOrder(List<List<Integer>> nums) {
List<Deque<Integer>> mat = new ArrayList<>();
int n = 0, k = 0;
for (int i = 0; i < nums.size(); i++) {
List<Integer> row = nums.get(i);
for (int j = 0; j < row.size(); j++, n++) {
if (i + j >= mat.size()) mat.add(new ArrayDeque());
mat.get(i + j).push(row.get(j));
}
}
int[] res = new int[n];
for (Deque<Integer> diag : mat) {
for (int num : diag) {
res[k++] = num;
}
}
return res;
}
}