We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b823831 commit 6114e50Copy full SHA for 6114e50
1424-diagonal-traverse-ii.js
@@ -0,0 +1,27 @@
1
+/**
2
+ * @param {number[][]} nums
3
+ * @return {number[]}
4
+ */
5
+const findDiagonalOrder = function(nums) {
6
+ const m = nums.length
7
+ const map = new Map()
8
+ let maxKey = 0
9
+ for(let i = 0; i < m; i++) {
10
+ for(let j = 0, n = nums[i].length; j < n; j++) {
11
+ if(!map.has(i + j)) map.set(i + j, [])
12
+ map.get(i + j).push(nums[i][j])
13
+ maxKey = Math.max(maxKey, i + j)
14
+ }
15
16
+ // console.log(map)
17
+ const res = []
18
+ for(let i = 0; i <= maxKey; i++) {
19
+ if(map.has(i)) {
20
+ const tmp = map.get(i)
21
+ tmp.reverse()
22
+ res.push(...tmp)
23
24
25
+
26
+ return res
27
+};
0 commit comments