File tree 3 files changed +62
-1
lines changed
3 files changed +62
-1
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val, left, right) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.left = (left===undefined ? null : left)
6
+ * this.right = (right===undefined ? null : right)
7
+ * }
8
+ */
9
+ /**
10
+ * @param {TreeNode } root
11
+ * @return {number }
12
+ */
13
+ const maxDepth = ( root ) => {
14
+ let depth = 0 ;
15
+
16
+ const dfs = ( currNode , tmpDepth ) => {
17
+ if ( null !== currNode ) {
18
+ tmpDepth ++ ;
19
+ dfs ( currNode . left , tmpDepth ) ;
20
+ dfs ( currNode . right , tmpDepth ) ;
21
+ } else {
22
+ depth = Math . max ( depth , tmpDepth ) ;
23
+ return ;
24
+ }
25
+ }
26
+
27
+ dfs ( root , 0 ) ;
28
+
29
+ return depth ;
30
+ } ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val, left, right) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.left = (left===undefined ? null : left)
6
+ * this.right = (right===undefined ? null : right)
7
+ * }
8
+ */
9
+ /**
10
+ * @param {TreeNode } root
11
+ * @return {number }
12
+ */
13
+ const maxDepth = ( root ) => {
14
+ let depth = 0 ;
15
+
16
+ const dfs = ( currNode , tmpDepth ) => {
17
+ if ( null !== currNode ) {
18
+ tmpDepth ++ ;
19
+ dfs ( currNode . left , tmpDepth ) ;
20
+ dfs ( currNode . right , tmpDepth ) ;
21
+ } else {
22
+ depth = Math . max ( depth , tmpDepth ) ;
23
+ return ;
24
+ }
25
+ }
26
+
27
+ dfs ( root , 0 ) ;
28
+
29
+ return depth ;
30
+ } ;
Original file line number Diff line number Diff line change 36
36
- [ 76. Minimum Window Substring] ( ./76/ )
37
37
- [ 79. Word Search] ( ./79/ )
38
38
- [ 83. Remove Duplicates from Sorted List] ( ./83/ )
39
+ - [ 104. Maximum Depth of Binary Tree] ( ./104/ )
39
40
- [ 121. Best Time to Buy and Sell Stock] ( ./121/ )
40
41
- [ 128. Longest Consecutive Sequence] ( ./128/ )
41
42
- [ 133. Clone Graph] ( ./133/ )
@@ -136,7 +137,7 @@ Batch create:
136
137
NOTE: JS IS HERE
137
138
-->
138
139
``` ssh
139
- chapter=714 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
140
+ chapter=104 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
140
141
```
141
142
> then you can use ` x ` for quick debug.
142
143
You can’t perform that action at this time.
0 commit comments