Skip to content

Commit 516b167

Browse files
author
QianYuTing
committed
add the solution of Maximum Depth of Binary Tree(104) with Javascript.
1 parent 475d73f commit 516b167

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
| [088][088-question] | [Merge Sorted Array][088-tips] | [Easy][E] | [][088-java] | [][088-js] | [][088-kotlin] |
7676
| [100][100-question] | [Same Tree][100-tips] | [Easy][E] | [][100-java] | [][100-js] | [][100-kotlin] |
7777
| [101][101-question] | [Symmetric Tree][101-tips] | [Easy][E] | [][101-java] | [][101-js] | [][101-kotlin] |
78-
| [104][104-question] | [Maximum Depth of Binary Tree][104-tips] | [Easy][E] | [][104-java] | | [][104-kotlin] |
78+
| [104][104-question] | [Maximum Depth of Binary Tree][104-tips] | [Easy][E] | [][104-java] | [][104-js] | [][104-kotlin] |
7979
| [107][107-question] | [Binary Tree Level Order Traversal II][107-tips] | [Easy][E] | [][107-java] | | [][107-kotlin] |
8080
| [108][108-question] | [Convert Sorted Array to Binary Search Tree][108-tips] | [Easy][E] | [][108-java] | | [][108-kotlin] |
8181
| [110][110-question] | [Balanced Binary Tree][110-tips] | [Easy][E] | [][110-java] | | [][110-kotlin] |
@@ -455,6 +455,7 @@ commit信息模板: ``feat: add the solution of `Two Sum`(001) with Java``
455455
[088-js]: ./src/_088/Solution.js
456456
[100-js]: ./src/_100/Solution.js
457457
[101-js]: ./src/_101/Solution.js
458+
[104-js]: ./src/_104/Solution.js
458459
[226-js]: ./src/_226/Solution.js
459460
[561-js]: ./src/_561/Solution.js
460461
[643-js]: ./src/_643/Solution.js

src/_104/Solution.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 == null) return 0;
14+
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
15+
};

0 commit comments

Comments
 (0)