File tree 6 files changed +75
-2
lines changed
6 files changed +75
-2
lines changed Original file line number Diff line number Diff line change 76
76
| [ 100] [ 100-question ] | [ Same Tree] [ 100-tips ] | [ Easy] [ E ] | [ ✅] [ 100-java ] | [ ✅] [ 100-js ] | [ ✅] [ 100-kotlin ] |
77
77
| [ 101] [ 101-question ] | [ Symmetric Tree] [ 101-tips ] | [ Easy] [ E ] | [ ✅] [ 101-java ] | [ ✅] [ 101-js ] | [ ✅] [ 101-kotlin ] |
78
78
| [ 104] [ 104-question ] | [ Maximum Depth of Binary Tree] [ 104-tips ] | [ Easy] [ E ] | [ ✅] [ 104-java ] | [ ✅] [ 104-js ] | [ ✅] [ 104-kotlin ] |
79
- | [ 107] [ 107-question ] | [ Binary Tree Level Order Traversal II] [ 107-tips ] | [ Easy] [ E ] | [ ✅] [ 107-java ] | | [ ✅] [ 107-kotlin ] |
80
- | [ 108] [ 108-question ] | [ Convert Sorted Array to Binary Search Tree] [ 108-tips ] | [ Easy] [ E ] | [ ✅] [ 108-java ] | | [ ✅] [ 108-kotlin ] |
79
+ | [ 107] [ 107-question ] | [ Binary Tree Level Order Traversal II] [ 107-tips ] | [ Easy] [ E ] | [ ✅] [ 107-java ] | [ ✅ ] [ 107-js ] | [ ✅] [ 107-kotlin ] |
80
+ | [ 108] [ 108-question ] | [ Convert Sorted Array to Binary Search Tree] [ 108-tips ] | [ Easy] [ E ] | [ ✅] [ 108-java ] | [ ✅ ] [ 108-js ] | [ ✅] [ 108-kotlin ] |
81
81
| [ 110] [ 110-question ] | [ Balanced Binary Tree] [ 110-tips ] | [ Easy] [ E ] | [ ✅] [ 110-java ] | | [ ✅] [ 110-kotlin ] |
82
82
| [ 111] [ 111-question ] | [ Minimum Depth of Binary Tree] [ 111-tips ] | [ Easy] [ E ] | [ ✅] [ 111-java ] | | [ ✅] [ 111-kotlin ] |
83
83
| [ 112] [ 112-question ] | [ Path Sum] [ 112-tips ] | [ Easy] [ E ] | [ ✅] [ 112-java ] | | [ ✅] [ 112-kotlin ] |
@@ -456,6 +456,8 @@ commit信息模板: ``feat: add the solution of `Two Sum`(001) with Java``
456
456
[ 100-js ] : ./src/_100/Solution.js
457
457
[ 101-js ] : ./src/_101/Solution.js
458
458
[ 104-js ] : ./src/_104/Solution.js
459
+ [ 107-js ] : ./src/_107/Solution.js
460
+ [ 108-js ] : ./src/_108/Solution.js
459
461
[ 226-js ] : ./src/_226/Solution.js
460
462
[ 561-js ] : ./src/_561/Solution.js
461
463
[ 643-js ] : ./src/_643/Solution.js
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val) {
4
+ * this.val = val;
5
+ * this.left = this.right = null;
6
+ * }
7
+ */
8
+ /**
9
+ * @param {number[] } nums
10
+ * @return {TreeNode }
11
+ */
12
+ var sortedArrayToBST = function ( nums ) {
13
+ if ( nums == null || ! nums . length ) {
14
+ return null ;
15
+ }
16
+ let mid = Math . floor ( nums . length / 2 )
17
+ let rootNode = new TreeNode ( nums [ mid ] )
18
+ rootNode . left = sortedArrayToBST ( nums . slice ( 0 , mid ) )
19
+ rootNode . right = sortedArrayToBST ( nums . slice ( mid + 1 ) )
20
+ return rootNode
21
+ } ;
Original file line number Diff line number Diff line change @@ -78,6 +78,19 @@ class Solution {
78
78
}
79
79
```
80
80
81
+
82
+ ``` javascript
83
+ var isSymmetric = function (root ) {
84
+ if (root == null ) return true
85
+ var x = function (left , right ) {
86
+ if (left == null && right == null ) return true
87
+ if (left == null || right == null ) return false
88
+ if (left .val !== right .val ) return false ;
89
+ return x (left .left , right .right ) && x (left .right , right .left )
90
+ }
91
+ return x (root .left , root .right )
92
+ };
93
+ ```
81
94
## 思路 1
82
95
83
96
第二种思路就是宽搜了,宽搜肯定要用到队列,Java 中可用 ` LinkedList ` 替代,也是要做到左子树的左节点和右子树的右节点,左子树的右节点和右子树的左节点做比较即可。
Original file line number Diff line number Diff line change @@ -44,6 +44,12 @@ class Solution {
44
44
}
45
45
```
46
46
47
+ ``` javascript
48
+ var maxDepth = function (root ) {
49
+ if (root == null ) return 0 ;
50
+ return 1 + Math .max (maxDepth (root .left ), maxDepth (root .right ));
51
+ };
52
+ ```
47
53
## 结语
48
54
49
55
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[ LeetCode-Solution] [ ls ]
Original file line number Diff line number Diff line change @@ -119,6 +119,25 @@ class Solution {
119
119
}
120
120
```
121
121
122
+ ``` javascript
123
+ var levelOrderBottom = function (root ) {
124
+ if (root === null ) { return []; }
125
+ let result = [];
126
+ let queue = [root];
127
+ while (queue .length > 0 ) {
128
+ let size = queue .length ;
129
+ let current = [];
130
+ for (let i = 0 ; i < size; i++ ) {
131
+ let head = queue .shift ();
132
+ current .push (head .val );
133
+ if (head .left !== null ) { queue .push (head .left ); }
134
+ if (head .right !== null ) { queue .push (head .right ); }
135
+ }
136
+ result .unshift (current);
137
+ }
138
+ return result;
139
+ };
140
+ ```
122
141
## 结语
123
142
124
143
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[ LeetCode-Solution] [ ls ]
Original file line number Diff line number Diff line change @@ -85,6 +85,18 @@ class Solution {
85
85
}
86
86
```
87
87
88
+ ``` javascript
89
+ var sortedArrayToBST = function (nums ) {
90
+ if (nums == null || ! nums .length ) {
91
+ return null ;
92
+ }
93
+ let mid = Math .floor (nums .length / 2 )
94
+ let rootNode = new TreeNode (nums[mid])
95
+ rootNode .left = sortedArrayToBST (nums .slice (0 , mid))
96
+ rootNode .right = sortedArrayToBST (nums .slice (mid+ 1 ))
97
+ return rootNode
98
+ };
99
+ ```
88
100
## 结语
89
101
90
102
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[ LeetCode-Solution] [ ls ]
You can’t perform that action at this time.
0 commit comments