基础的2叉树题。代码如下:
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
depth = 0
if root == None:
return 0
else:
return 1 + depth + max(self.maxDepth(root.right), self.maxDepth(root.left))