Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def maxDepth(self, root: Optional[TreeNode]) -> int:
- if not root:
- return 0
- return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
- class Solution:
- def maxDepth(self, root: Optional[TreeNode]) -> int:
- if root is None:
- return 0
- left_count = self.maxDepth(root.left)
- right_count = self.maxDepth(root.right)
- return 1 + max(left_count, right_count)
Advertisement
Add Comment
Please, Sign In to add comment