赞
踩
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution(object): def maxDepth(self, root): """ :type root: TreeNode :rtype: int """ # 节点为空则返回0 if not root: return 0 else: return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。