题解 | #二叉树的深度 Python#
二叉树的深度
http://www.nowcoder.com/practice/435fb86331474282a3499955f0a41e8b
- 用递归思想
class Solution:
def TreeDepth(self, pRoot):
# write code here
if not pRoot:
return 0
left = self.TreeDepth(pRoot.left) + 1
right = self.TreeDepth(pRoot.right) + 1
return max(left, right)