[leetcode刷题系列]Minimum Depth of Binary Tree
来源:互联网 发布:mac 免费uml建模工具 编辑:程序博客网 时间:2024/05/19 13:44
- - 不说了
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution { void dfs(TreeNode * root, int now, int & ans){ if(root->left == 0 && root->right == 0){ if(ans == -1 || now < ans) ans = now; return ; } if(root->left != 0) dfs(root->left, now + 1, ans); if(root->right != 0) dfs(root->right, now + 1, ans); }public: int minDepth(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if(root == 0) return 0; int ans = -1; dfs(root, 1, ans); return ans; }};
- [leetcode刷题系列]Minimum Depth of Binary Tree
- LeetCode刷题笔录Minimum Depth of Binary Tree
- 开始刷题 leetcode day8: Minimum Depth of Binary Tree
- 【Leetcode长征系列】Minimum Depth of Binary Tree
- LeetCode: Minimum Depth of Binary Tree
- [Leetcode] Minimum Depth of Binary Tree
- LeetCode : Minimum Depth of Binary Tree
- leetcode 31: Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - BFS
- [LeetCode] Minimum Depth of Binary Tree - DFS
- 【leetcode】Minimum Depth of Binary Tree
- LeetCode:Minimum Depth of Binary Tree
- [LeetCode]Minimum Depth of Binary Tree
- [Leetcode]Minimum Depth of Binary Tree
- [leetcode]Minimum Depth of Binary Tree
- Leetcode: Minimum Depth of Binary Tree
- LeetCode-Minimum Depth of Binary Tree
- [leetcode] Minimum Depth of Binary Tree
- 看截图:给图片罩上一层半透明文字描述效果(一)DIV+CSS+SPAN 借鉴百度图片附着文字效果
- NYOJ 85题 有趣的数
- Struts2常用标签总结
- hdu 1673 Optimal Parking
- 03-打印访问者的IP地址
- [leetcode刷题系列]Minimum Depth of Binary Tree
- Oracle 11g启动服务,账户被锁定等问题的解决
- HDU 1531 差分约束
- 黑马程序员_IO输入输出流
- 手机电池电量
- 批处理文件
- 《教你玩魔方》
- 亚马逊Kindle入华的挑战
- Java Ant build.xml详解