leetcode_题解_Minimum Depth of Binary Tree _easy需细心
来源:互联网 发布:centos mysql默认密码 编辑:程序博客网 时间:2024/05/21 15:01
参考了leetcode题解那本书的:
需要注意:和max depth稍不同,这里注意叶子节点的概念,不要弄错了。
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution { private: int isROOT=1;public: int minDepth(TreeNode *root) { return minDepth(root,false); }private: int minDepth(TreeNode *root,bool hasBrother) { if(!root) return hasBrother?INT_MAX:0; else return 1+min(minDepth(root->left,root->right!=NULL),minDepth(root->right,root->left!=NULL)); }};
0 0
- leetcode_题解_Minimum Depth of Binary Tree _easy需细心
- leetcode第一刷_Minimum Depth of Binary Tree
- leetcode_题解_Maximum Depth of Binary Tree_简单题
- LeetCode题解:Maximum Depth of Binary Tree
- LeetCode题解:Minimum Depth of Binary Tree
- LeetCode题解:Minimum Depth of Binary Tree
- LeetCode题解:Maximum Depth of Binary Tree
- LeetCode题解:Maximum Depth of Binary Tree
- Depth of binary tree
- LeetCode 题解(12):Maximum Depth of Binary Tree
- 【LeetCode】【Python题解】Single Number & Maximum Depth of Binary Tree
- leetcode Minimum Depth of Binary Tree C++题解
- LeetCode 题解(220) : Minimum Depth of Binary Tree
- [81][E][leetcode 题解]Minimum Depth of Binary Tree
- Leetcode题解 104. Maximum Depth of Binary Tree
- Leetcode题解 111. Minimum Depth of Binary Tree
- LeetCode题解-104-Maximum Depth of Binary Tree
- LeetCode题解-111-Minimum Depth of Binary Tree
- C++学习:模板编译模式
- 专注Android移动开发,热爱分享,支持开源
- 自定义横向的ScrollView
- 产品经理学习笔记(9)-产品经理离用户有多远
- JavaMail 接收邮件(解码技术和附件接收)
- leetcode_题解_Minimum Depth of Binary Tree _easy需细心
- cocos2d-x-3.x 修改和纪录
- 解决IE6下top&fixed无效问题
- DLL+ ActiveX控件+WEB页面调用例子
- 产品经理学习笔记(10)-到用户中去:找到你的核心用户
- 一个项目经理的个人体会( 转)
- 产品经理学习笔记(11)用户调研的方法
- 不妨将公共单车纳入公交系统
- HandlerThread初步使用