111. Minimum Depth of Binary Tree
来源:互联网 发布:sizeof数组 编辑:程序博客网 时间:2024/05/20 17:10
参考链接:
点击打开链接
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int minDepth(TreeNode* root) { if(root == NULL){ return 0; } int dl = minDepth(root->left); //不断迭代向下 int dr = minDepth(root->right); //自底向上的计算高度 //当前位置高度为零,也就是底层空节点, if(!dl){ return dr +1; } if(!dr){ return dl + 1; } return (dl>dr)?dr+1:dl+1; }};
阅读全文
0 0
- LeetCode 111. Minimum Depth of Binary Tree
- [LeetCode]111.Minimum Depth of Binary Tree
- 【LeetCode】111.Minimum Depth of Binary Tree
- [Leetcode] 111. Minimum Depth of Binary Tree
- 111.Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- [leetcode] 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree LeetCode
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 【LeetCode】111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- LeetCode *** 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- vue-cli构建vue项目
- React Native相机 相册 定位 设备信息
- 图的搜索和最短路径-Saving James Bond
- Cadence中的PCB Editor如何关闭已经所敷铜的显示(多说无益,如图所示)
- js如何禁止掉网页上的鼠标右击事件
- 111. Minimum Depth of Binary Tree
- html 基础标签
- 刷清橙OJ--A1030.球队排名
- 移动web开发笔记01
- App开放接口api安全性—Token签名sign的设计与实现
- 纪念:毕业不到一年 裸辞了
- 拼接option,并给其中一个option赋值
- 打开远程桌面命令
- 银行VIP客户人脸识别系统--基于深度学习