Advertisement
jinhuang1102

104. Maximum Depth of Binary Tree

Mar 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. class Solution(object):
  2.     def maxDepth(self, root):
  3.         """
  4.        :type root: TreeNode
  5.        :rtype: int
  6.        """
  7.         if not root:
  8.             return 0
  9.        
  10.         left = self.maxDepth(root.left)
  11.         right = self.maxDepth(root.right)
  12.         res = max(left, right) + 1
  13.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement