Skip to content

Commit e8edc96

Browse files
Create 1424-diagonal-traverse-ii.java
1 parent b4dec61 commit e8edc96

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: java/1424-diagonal-traverse-ii.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public int[] findDiagonalOrder(List<List<Integer>> nums) {
3+
Map<Integer, List<Integer>> map = new HashMap<>();
4+
int n = 0;
5+
for(int i = nums.size()-1; i >= 0; i--){
6+
for(int j = 0; j < nums.get(i).size(); j++){
7+
n++;
8+
if(!map.containsKey(i+j)){
9+
map.put(i+j, new ArrayList<>());
10+
}
11+
map.get(i+j).add(nums.get(i).get(j));
12+
}
13+
}
14+
int[] res = new int[n];
15+
int idx = 0;
16+
int curr = 0;
17+
while(map.containsKey(curr)){
18+
for(int num: map.get(curr)){
19+
res[idx] = num;
20+
idx++;
21+
}
22+
curr++;
23+
}
24+
return res;
25+
}
26+
}

0 commit comments

Comments
 (0)