File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * @lc app=leetcode id=104 lang=javascript
3+ *
4+ * [104] Maximum Depth of Binary Tree
5+ */
6+
7+ // @lc code=start
8+ /**
9+ * Definition for a binary tree node.
10+ * function TreeNode(val, left, right) {
11+ * this.val = (val===undefined ? 0 : val)
12+ * this.left = (left===undefined ? null : left)
13+ * this.right = (right===undefined ? null : right)
14+ * }
15+ */
16+ /**
17+ * @param {TreeNode } root
18+ * @return {number }
19+ */
20+ let maxDepth = function ( root ) {
21+ let max = 0
22+ let helper = ( node , depth ) => {
23+ if ( ! node ) return
24+ max = Math . max ( max , depth )
25+ if ( node . left ) {
26+ helper ( node . left , depth + 1 )
27+ }
28+ if ( node . right ) {
29+ helper ( node . right , depth + 1 )
30+ }
31+ }
32+ helper ( root , 1 )
33+ return max
34+ }
35+ // @lc code=end
You can’t perform that action at this time.
0 commit comments