Skip to content

Commit baf7900

Browse files
Added max-depth
1 parent 877ecdb commit baf7900

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

max_depth.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.left = None
6+
# self.right = None
7+
8+
class Solution:
9+
def maxDepth(self, root: TreeNode) -> int:
10+
if not root:
11+
return 0
12+
13+
return 1 + max(self.maxDepth(root.left), self.maxDepth( root.right))

0 commit comments

Comments
 (0)