Maximum Depth of Binary Tree
Example
1
/ \
2 3
/ \
4 5class Solution(object):
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if not root:
return 0
return 1+max(self.maxDepth(root.left), self.maxDepth(root.right))Last updated