/*** Definition for binary tree* struct TreeNode {*     int val;*     TreeNode *left;*     TreeNode *right;*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}* };*//*求二叉树的最小深度*/
class Solution {
public:int res = INT_MAX;void dfs(TreeNode *root,int depth){if(!root||depth>=res) return;//剪枝,当前搜索深度大于最小值就不要继续往下搜了if(!root->left &&!root->right){res = min(res,depth+1);return ;}dfs(root->left,depth+1);dfs(root->right,depth+1);return ;}int minDepth(TreeNode *root) {if(!root) return 0;dfs(root,0);return res;}
};

转载于:https://www.cnblogs.com/llei1573/p/4345214.html

Minimum Depth of Binary Tree相关推荐

  1. LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree

    LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...

  2. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  3. leetcode - Minimum Depth of Binary Tree

    题目:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is th ...

  4. LeetCode: 111. Minimum Depth of Binary Tree

    题目 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bina ...

  5. LeetCode Minimum Depth of Binary Tree

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  6. 【Minimum Depth of Binary Tree】cpp

    题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...

  7. LeetCode 111. Minimum Depth of Binary Tree

    原题 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the s ...

  8. [LeetCode] Minimum Depth of Binary Tree

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  9. C#LeetCode刷题之#111-二叉树的最小深度​​​​​​​(Minimum Depth of Binary Tree)

    问题 给定一个二叉树,找出其最小深度. 最小深度是从根节点到最近叶子节点的最短路径上的节点数量. 说明: 叶子节点是指没有子节点的节点. 给定二叉树 [3,9,20,null,null,15,7], ...

  10. leetcode python3 简单题111. Minimum Depth of Binary Tree

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百一十一题 (1)题目 英文: Given a binary tree, fin ...

最新文章

  1. 寄存器和常用的汇编指令
  2. 清华大学软件定义芯片团队的高能效量化卷积神经网络加速芯片入选固态电路顶级会议ISSCC 2021...
  3. C语言OJ项目参考(2399)求倒数和
  4. LeetCode-字符串-反转字符串中的单词 II
  5. 【若依(ruoyi)】弹框图标 / layer 图标
  6. remote_os_authent参数测试!
  7. w ndows7与XP哪个好,windows7和xp哪个好 windows7好用吗
  8. go语言最好的帮助在哪里?
  9. 二十九、layui分页插件的使用
  10. Paip.提升用户体验------在C++ Builder 不规则图片按钮实现总结
  11. 数据治理之数据发现-元数据-DataHub
  12. ITween操作API
  13. r矢量球坐标系旋度_6矢量分析:旋度、散度、梯度.ppt
  14. android 添加前景色
  15. 太原师范学院计算机考研资料汇总
  16. HTML+CSS - 侧边导航栏
  17. pythonSSL证书 cookie session
  18. 扫地机器人(简单路径规划)
  19. alibab的滑动验证
  20. 利用js写的见缝插针小游戏

热门文章

  1. python爬虫流程-Python爬虫入门
  2. python基础知识整理-Python3基础知识(一)
  3. python怎么安装matplotlib-如何安装Python绘图库Matplotlib?
  4. python编程入门 电子书-Python编程从入门到实践PDF电子书
  5. 安卓手机可以用python编程软件-python可以编写手机应用吗
  6. 笨办法学python3-笨方法学Python3(21-44)
  7. python语法基础知识-python基础知识---简单语法
  8. python小游戏编程实例-Python实现的弹球小游戏示例
  9. python版本选择-【小白学python】之一:版本选择
  10. 通过python建立一个web服务查看服务器上的文本、图片、视频等文件