Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16444de

Browse files
committed
update: 103
1 parent99292bc commit16444de

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
6262
| 100|[Same Tree](https://leetcode.com/problems/same-tree/)|[JavaScript](./src/same-tree/res.js)| Easy|
6363
| 101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/)|[JavaScript](./src/symmetric-tree/res.js)| Easy|
6464
| 102|[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/)|[JavaScript](./src/binary-tree-level-order-traversal/res.js)| Medium|
65+
| 103|[binary-tree-zigzag-level-order-traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/)|[TypeScript](./src/binary-tree-zigzag-level-order-traversal/res.ts)| Medium|
6566
| 104|[Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)|[JavaScript](./src/maximum-depth-of-binary-tree/res.js)| Easy|
6667
| 107|[Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii/)|[JavaScript](./src/binary-tree-level-order-traversal-ii/res.js)| Easy|
6768
| 108|[Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/)|[JavaScript](./src/convert-sorted-array-to-binary-search-tree/res.js)| Easy|
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Definition for a binary tree node.
3+
*/
4+
classTreeNode{
5+
val:number
6+
left:TreeNode|null
7+
right:TreeNode|null
8+
constructor(val?:number,left?:TreeNode|null,right?:TreeNode|null){
9+
this.val=(val===undefined ?0 :val)
10+
this.left=(left===undefined ?null :left)
11+
this.right=(right===undefined ?null :right)
12+
}
13+
}
14+
15+
functionzigzagLevelOrder(root:TreeNode|null):number[][]{
16+
constresult=[];
17+
letqueues=[root];
18+
letreverse=true;
19+
20+
if(!root){
21+
returnresult;
22+
}
23+
24+
while(queues.length){
25+
constcurrentLevel=queues.slice();
26+
constcurrentLevelList=[];
27+
queues=[];
28+
reverse=!reverse;
29+
30+
for(leti=0;i<currentLevel.length;i++){
31+
constcurrentNode=currentLevel[i];
32+
currentLevelList.push(currentNode.val);
33+
34+
if(currentNode.left){
35+
queues.push(currentNode.left);
36+
}
37+
if(currentNode.right){
38+
queues.push(currentNode.right);
39+
}
40+
}
41+
42+
result.push(reverse ?currentLevelList.reverse() :currentLevelList);
43+
}
44+
45+
returnresult;
46+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp