ICode9

精准搜索请尝试: 精确搜索
  • 力扣简111 二叉树的最小深度2022-05-21 21:31:25

    最开始忽略了左子树为空还得计算右子树的叶子节点深度,直接分为左空右空和其他,对于其他认为直接返回0,导致会直接归入其他而报错! 改正后效果也挺一般:     package leetcode01; //给定一个二叉树,找出其最小深度。最小深度是从根节点到最近叶子节点的最短路径上的节点数量。 publ

  • 111. 二叉树的最小深度2021-10-27 19:04:08

    class Solution { public int minDepth(TreeNode root) { if (root == null){ return 0; } int left = minDepth(root.left); int right = minDepth(root.right); /** * 如果左右孩子有一个没有,那就只计算另

  • LeetCode-111-二叉树的最小深度2021-07-15 08:35:16

    二叉树的最小深度 题目描述:给定一个二叉树,找出其最小深度。 最小深度是从根节点到最近叶子节点的最短路径上的节点数量。 说明:叶子节点是指没有子节点的节点。 示例说明请见LeetCode官网。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/

  • LeetCode 111 二叉树最小深度2020-08-09 10:32:05

    Leetcode 111 二叉树最小深度 给定一颗二叉树,求根节点到叶子节点的最短路径(最小深度) class Solution{ public int minDepth(TreeNode root){ //若无根节点(空树),则返回0 if(root==null) { return 0; } //叶子节点,向上返回1,递归

  • minDepth2020-06-06 18:09:07

    给定一个二叉树,找出其最小深度。 最小深度是从根节点到最近叶子节点的最短路径上的节点数量。 说明: 叶子节点是指没有子节点的节点。 示例: 给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回它的最小深度  2. /** * Definition for

  • 【树】111. 二叉树的最小深度2020-05-02 13:00:55

    题目:     解答: 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */ 10 class Solution

  • LeetCode_111. Minimum Depth of Binary Tree2019-10-02 15:50:26

      111. Minimum Depth of Binary Tree Easy Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example

  • 二叉树的最大、最小深度2019-09-16 15:06:49

    104.最大深度 class Solution { public int maxDepth(TreeNode root) { //结点为空返回0 if(root==null){ return 0 ; }else{ //递归左子树 int ld = maxDepth(root.left); //递归右

  • 111.二叉树的最小深度2019-09-03 19:02:36

    # Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: def minDepth(self, root: TreeNode) -> int: if root is None:

  • shell 删除除匹配字符串之外的所有文件夹2019-07-24 17:04:47

    file_dir=`find 目录 -mindepth 1 -maxdepth 5 - type d`for dir in $file_dirdo   file_name=`basename $dir`  if [ $file_name != "目标文件名" ];then    rm -rf $dir    if [ $? != 0 ];then      echo "未删除成功!"      exit -2    fi  fidon

  • [LeetCode] 111. 二叉树的最小深度2019-06-29 18:50:44

    题目链接 : https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/ 题目描述: 给定一个二叉树,找出其最小深度。 最小深度是从根节点到最近叶子节点的最短路径上的节点数量。 说明: 叶子节点是指没有子节点的节点。 示例: 给定二叉树 [3,9,20,null,null,15,7], 3

  • 【LeetCode】Minimum Depth of Binary Tree(二叉树的最小深度)2019-05-01 21:53:22

    这道题是LeetCode里的第111道题。 题目描述: 给定一个二叉树,找出其最小深度。 最小深度是从根节点到最近叶子节点的最短路径上的节点数量。 说明: 叶子节点是指没有子节点的节点。 示例: 给定二叉树 [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返

  • leetcode 104. Maximum Depth of Binary Tree 111. Minimum Depth of Binary Tree2019-04-07 15:49:20

    104: class Solution {public: int maxDepth(TreeNode* root) { if(root == NULL) return 0; int left = maxDepth(root->left); int right = maxDepth(root->right); return (left > right ? left : right) + 1; }};

  • leetcode111二叉树最小深度2019-02-18 19:02:45

    深搜,左分支或右分支不存在时,找另一边,当到达叶子结点时返回0,两边都有分支时取当中最小值。顶层也算一层所以每次递归(划分成新的树)时都要进行+1 代码 class Solution { public:int minDepth(TreeNode* root) { if (root == NULL) { return 0; }

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有