-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1424. Diagonal Traverse II
More file actions
44 lines (32 loc) · 918 Bytes
/
1424. Diagonal Traverse II
File metadata and controls
44 lines (32 loc) · 918 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
class Solution {
public int[] findDiagonalOrder(List<List<Integer>> nums)
{
int n = nums.size();
int count = 0;
ArrayList<List<Integer>> list = new ArrayList<>();
for (int i = 0; i < n; i++)
{
List<Integer> row = nums.get(i);
for (int j = 0; j < row.size(); j++)
{
int idx = i + j;
if (list.size() < idx + 1)
{
list.add(new ArrayList<>());
}
list.get(idx).add(row.get(j));
count ++;
}
}
int[] res = new int[count];
int idx = 0;
for (List<Integer> x : list)
{
for (int i = x.size() - 1; i >= 0; i--)
{
res[idx++] = x.get(i);
}
}
return res;
}
}