题解 | #二叉树的深度#
二叉树的深度
https://www.nowcoder.com/practice/435fb86331474282a3499955f0a41e8b
# -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def TreeDepth(self, pRoot): # write code here # 如果为空树 if pRoot == None: return 0 # 分别记录左子树 和 右子树的高度 l = self.TreeDepth(pRoot.left) r = self.TreeDepth(pRoot.right) if l >= r: return l + 1 else: return r + 1#23届找工作求助阵地#