leetcode——104. 二叉树的最大深度

同111题

class Solution(object):
    def maxDepth(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        if not root:
            return 0
        left = self.maxDepth(root.left) 
        right = self.maxDepth(root.right) 
        return max(left,right)+1 
执行用时 :32 ms, 在所有 python 提交中击败了76.27%的用户
内存消耗 :14.7 MB, 在所有 python 提交中击败了23.02%的用户
——2019.11.15
 

public int maxDepth(TreeNode root) {
        if(root == null){
            return 0;
        }
        return 1+Math.max(maxDepth(root.left),maxDepth(root.right));
    }

 

 

——2020.7.2

posted @ 2019-11-15 11:12  欣姐姐  阅读(144)  评论(0编辑  收藏  举报