Skip to content

Commit aa6b615

Browse files
committed
78
1 parent 66e4874 commit aa6b615

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

Day78/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @param {number[][]} matrix
3+
* @return {number[]}
4+
*/
5+
var findDiagonalOrder = function(matrix) {
6+
7+
if(!matrix.length)return []
8+
let r = matrix.length;
9+
let c = matrix[0].length;
10+
11+
let map = {};
12+
13+
for(let i=0; i < r; i++){
14+
for(let j =0; j < c; j++){
15+
16+
let key = i+j;
17+
18+
if(!(key in map))map[key] = [];
19+
map[key].push(matrix[i][j])
20+
}
21+
}
22+
23+
24+
let res = [];
25+
console.log(map)
26+
27+
let len = Object.keys(map).length;
28+
let flag = true;
29+
30+
for(let i=0; i < len; i++){
31+
if(i <=1){
32+
res.push(...map[i])
33+
}else if(flag){
34+
let data = map[i].reverse();
35+
res.push(...data);
36+
flag = false
37+
}else{
38+
res.push(...map[i]);
39+
flag = true;
40+
}
41+
42+
43+
}
44+
return res
45+
46+
};

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,6 @@ If you are loving solving problems in leetcode, please contact me to enjoy it to
174174
|Day 76| [556. Next Greater Element III](https://leetcode.com/problems/next-greater-element-iii/) | [javascript]()|[:memo:](https://leetcode.com/problems/next-greater-element-iii/)|Medium|
175175

176176

177-
|Day 77| [24. Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) | [javascript]()|[:memo:](https://leetcode.com/problems/swap-nodes-in-pairs/)|Medium|
177+
|Day 77| [24. Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/) | [javascript]()|[:memo:](https://leetcode.com/problems/swap-nodes-in-pairs/)|Medium|
178+
179+
|Day 78| [498. Diagonal Traverse](https://leetcode.com/problems/diagonal-traverse/) | [javascript]()|[:memo:](https://leetcode.com/problems/diagonal-traverse/)|Medium|

0 commit comments

Comments
 (0)