Minimum Depth of Binary Tree
/*** 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相关推荐
- 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 ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- leetcode - Minimum Depth of Binary Tree
题目:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is th ...
- LeetCode: 111. Minimum Depth of Binary Tree
题目 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bina ...
- 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 ...
- 【Minimum Depth of Binary Tree】cpp
题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...
- 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 ...
- [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 ...
- C#LeetCode刷题之#111-二叉树的最小深度(Minimum Depth of Binary Tree)
问题 给定一个二叉树,找出其最小深度. 最小深度是从根节点到最近叶子节点的最短路径上的节点数量. 说明: 叶子节点是指没有子节点的节点. 给定二叉树 [3,9,20,null,null,15,7], ...
- leetcode python3 简单题111. Minimum Depth of Binary Tree
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百一十一题 (1)题目 英文: Given a binary tree, fin ...
最新文章
- 寄存器和常用的汇编指令
- 清华大学软件定义芯片团队的高能效量化卷积神经网络加速芯片入选固态电路顶级会议ISSCC 2021...
- C语言OJ项目参考(2399)求倒数和
- LeetCode-字符串-反转字符串中的单词 II
- 【若依(ruoyi)】弹框图标 / layer 图标
- remote_os_authent参数测试!
- w ndows7与XP哪个好,windows7和xp哪个好 windows7好用吗
- go语言最好的帮助在哪里?
- 二十九、layui分页插件的使用
- Paip.提升用户体验------在C++ Builder 不规则图片按钮实现总结
- 数据治理之数据发现-元数据-DataHub
- ITween操作API
- r矢量球坐标系旋度_6矢量分析:旋度、散度、梯度.ppt
- android 添加前景色
- 太原师范学院计算机考研资料汇总
- HTML+CSS - 侧边导航栏
- pythonSSL证书 cookie session
- 扫地机器人(简单路径规划)
- alibab的滑动验证
- 利用js写的见缝插针小游戏
热门文章
- python爬虫流程-Python爬虫入门
- python基础知识整理-Python3基础知识(一)
- python怎么安装matplotlib-如何安装Python绘图库Matplotlib?
- python编程入门 电子书-Python编程从入门到实践PDF电子书
- 安卓手机可以用python编程软件-python可以编写手机应用吗
- 笨办法学python3-笨方法学Python3(21-44)
- python语法基础知识-python基础知识---简单语法
- python小游戏编程实例-Python实现的弹球小游戏示例
- python版本选择-【小白学python】之一:版本选择
- 通过python建立一个web服务查看服务器上的文本、图片、视频等文件