55. 二叉树的深度
二叉树的深度
http://www.nowcoder.com/questionTerminal/435fb86331474282a3499955f0a41e8b
如果树只有一个节点,那么它的深度为1;如果根节点有左子树也有右子树,那么树的深度就是其左右子树深度的较大值再加1
class Solution:
def TreeDepth(self, pRoot):
# write code here
if pRoot is None:
return 0
count = max(self.TreeDepth(pRoot.left), self.TreeDepth(pRoot.right)) + 1
return count
查看11道真题和解析
