Skip to content

Commit bca70d0

Browse files
committed
Add solution #104
1 parent f19ddb7 commit bca70d0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
88|[Merge Sorted Array](./0088-merge-sorted-array.js)|Easy|
4343
94|[Binary Tree Inorder Traversal](./0094-binary-tree-inorder-traversal.js)|Easy|
4444
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|
4546
111|[Minimum Depth of Binary Tree](./0111-minimum-depth-of-binary-tree.js)|Easy|
4647
118|[Pascal's Triangle](./0118-pascals-triangle.js)|Easy|
4748
119|[Pascal's Triangle II](./0119-pascals-triangle-ii.js)|Easy|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
};

0 commit comments

Comments
 (0)