ツリーの最大深さ(python)--leetcode


ツリーに最大深さを指定します.
再帰解:
# 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
        """
        return self.treeDepth(root)
    def treeDepth(self, t):
        if t == None:
            return 0 
        ldepth = self.treeDepth(t.left)
        rdepth = self.treeDepth(t.right)
        return max(ldepth,rdepth)+1