Skip to content

Commit 15a9a1d

Browse files
committed
solved maximum depth of binary tree
1 parent 74f072a commit 15a9a1d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Time complexity : O(n)
2+
# Space complexity : O(n)
3+
class Solution:
4+
def maxDepth(self, root: Optional[TreeNode]) -> int:
5+
if not root:
6+
return 0
7+
8+
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))

0 commit comments

Comments
 (0)