zoukankan      html  css  js  c++  java
  • 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

    我的前方是万里征途,星辰大海!!
  • 相关阅读:
    2020-03-03
    2020-03-02
    2020-03-01
    2020-02-29
    简单自我介绍
    福大软工1816 · 第六次作业
    福大软工1816 · 第五次作业
    python爬虫解决编码问题
    第四次作业-团队介绍
    福大软工1816 · 第三次作业
  • 原文地址:https://www.cnblogs.com/taoyuxin/p/11865128.html
Copyright © 2011-2022 走看看