[leetcode tree]104. Maximum Depth of Binary Tree
求树的最大深度
1 class Solution(object): 2 def maxDepth(self, root): 3 if not root: 4 return 0 5 left = self.maxDepth(root.left) 6 right = self.maxDepth(root.right) 7 return left+1 if left>right else right+1
1 line python
1 class Solution(object): 2 def maxDepth(self, root): 3 return 1+max(map(self.maxDepth,(root.left,root.right))) if root else 0