leetcode——111. 二叉树的最小深度

0.。。。。

class Solution(object):
    def minDepth(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        if not root: return 0
        left = self.minDepth(root.left) 
        right = self.minDepth(root.right) 
        return left + right  + 1 if (left == 0 or right == 0) else min(left, right) + 1 
执行用时 :40 ms, 在所有 python 提交中击败了58.03%的用户
内存消耗 :14.6 MB, 在所有 python 提交中击败了39.41%的用户
——2019.11.15
 

复习:
public int minDepth(TreeNode root) {  //根节点到叶子节点的最小节点数
        if(root == null){
            return 0;
        }
        if(root.left == null && root.right == null) {
            return 1;
        }else if(root.left == null || root.right == null){
            return 1+Math.max(minDepth(root.left),minDepth(root.right));
        }else{
            return 1+Math.min(minDepth(root.left),minDepth(root.right));
        }
    }

——2020.7.2

我的前方是万里征途,星辰大海!!
原文地址:https://www.cnblogs.com/taoyuxin/p/11865128.html