Skip to content

Commit a7da2bd

Browse files
committed
adding max depth of binary tree
1 parent 8ca5562 commit a7da2bd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
3+
def maxDepth(self, root: Optional[TreeNode]) -> int:
4+
5+
if not root:
6+
return 0
7+
8+
left_depth = self.maxDepth(root.left)
9+
right_depth = self.maxDepth(root.right)
10+
11+
return max(left_depth, right_depth) + 1

0 commit comments

Comments
 (0)