File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 42
42
88|[ Merge Sorted Array] ( ./0088-merge-sorted-array.js ) |Easy|
43
43
94|[ Binary Tree Inorder Traversal] ( ./0094-binary-tree-inorder-traversal.js ) |Easy|
44
44
102|[ Binary Tree Level Order Traversal] ( ./0102-binary-tree-level-order-traversal.js ) |Medium|
45
+ 104|[ Maximum Depth of Binary Tree] ( ./0104-maximum-depth-of-binary-tree.js ) |Easy|
45
46
111|[ Minimum Depth of Binary Tree] ( ./0111-minimum-depth-of-binary-tree.js ) |Easy|
46
47
118|[ Pascal's Triangle] ( ./0118-pascals-triangle.js ) |Easy|
47
48
119|[ Pascal's Triangle II] ( ./0119-pascals-triangle-ii.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 104. Maximum Depth of Binary Tree
3
+ * https://leetcode.com/problems/maximum-depth-of-binary-tree/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given the root of a binary tree, return its maximum depth.
7
+ *
8
+ * A binary tree's maximum depth is the number of nodes along the longest
9
+ * path from the root node down to the farthest leaf node.
10
+ */
11
+
12
+ /**
13
+ * Definition for a binary tree node.
14
+ * function TreeNode(val, left, right) {
15
+ * this.val = (val===undefined ? 0 : val)
16
+ * this.left = (left===undefined ? null : left)
17
+ * this.right = (right===undefined ? null : right)
18
+ * }
19
+ */
20
+ /**
21
+ * @param {TreeNode } root
22
+ * @return {number }
23
+ */
24
+ var maxDepth = function ( root ) {
25
+ if ( ! root ) {
26
+ return 0 ;
27
+ }
28
+ const [ left , right ] = [ root . left , root . right ] . map ( maxDepth ) ;
29
+ return 1 + Math . max ( left , right ) ;
30
+ } ;
You can’t perform that action at this time.
0 commit comments