Skip to content

Commit dd9a296

Browse files
committed
Maximum Depth of Binary Tree solution
1 parent 161edcc commit dd9a296

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
# Maximum Depth of Binary Tree
3+
class Solution:
4+
def maxDepth(self, root: Optional[TreeNode]) -> int:
5+
if not root:
6+
return 0 # base case
7+
left = self.maxDepth(root.left)
8+
right = self.maxDepth(root.right)
9+
10+
return 1 + max(left, right)
11+
12+
# Time: O(n)
13+

0 commit comments

Comments
 (0)