【剑指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))