Leetcode

104. Maximum Depth of Binary Tre

2016-08-02  本文已影响9人  oo上海

104. Maximum Depth of Binary Tree

题目:
https://leetcode.com/problems/maximum-depth-of-binary-tree/

难度:

Easy

简单题


class Solution(object):
    def maxDepth(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        if root == None: return 0
        elif root.right == None and root.left == None: return 1
        else:
            return max(1 + self.maxDepth(root.left), 1+ self.maxDepth(root.right))
上一篇 下一篇

猜你喜欢

热点阅读