We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b4dec61 commit e8edc96Copy full SHA for e8edc96
java/1424-diagonal-traverse-ii.java
@@ -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