题解 | #二叉树的深度#
二叉树的深度
http://www.nowcoder.com/practice/435fb86331474282a3499955f0a41e8b
【剑指offer】二叉树的深度(python)
python 的三元运算符。“为真时的结果 if 判定条件 else 为假时的结果”
# -*- 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
return 0 if pRoot is None else 1+max(self.TreeDepth(pRoot.left),self.TreeDepth(pRoot.right))