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

Commit 2d9e782

Browse files
update: 104
1 parent cd361bc commit 2d9e782

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
5555
|100|[Same Tree](https://leetcode.com/problems/same-tree/) | [JavaScript](./src/same-tree/res.js)|Easy|
5656
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | [JavaScript](./src/symmetric-tree/res.js)|Easy|
5757
|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|
58+
|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|
5859
|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|
5960
|111|[Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | [JavaScript](./src/minimum-depth-of-binary-tree/res.js)|Easy|
6061
|120|[Triangle](https://leetcode.com/problems/triangle/) | [JavaScript](./src/triangle/res.js)|Medium|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 {TreeNode} root
10+
* @return {number}
11+
*/
12+
var maxDepth = function(root) {
13+
if (!root) return 0;
14+
15+
const getTreeDepth = (element) => {
16+
if (!element) return 0;
17+
if (element.val !== undefined && !element.left && !element.right) return 1;
18+
19+
return 1 + Math.max(getTreeDepth(element.left), getTreeDepth(element.right))
20+
}
21+
22+
return 1 + Math.max(getTreeDepth(root.left), getTreeDepth(root.right));
23+
};

‎src/same-tree/res.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* }
77
*/
88
/**
9+
* DFS
910
* @param {TreeNode} p
1011
* @param {TreeNode} q
1112
* @return {boolean}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /