111. Minimum Depth of Binary Tree
来源:互联网 发布:焦点访谈神乎大道堂 编辑:程序博客网 时间:2024/05/17 03:00
/*Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.*//** * 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) return 0; int leftD=minDepth(root->left); int rightD=minDepth(root->right); return (leftD==0 || rightD==0) ? leftD+rightD+1 : min(leftD,rightD)+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
- Play a game(巴什博弈丶找规律)
- Android进阶之View体系
- 九度[1107]-搬水果
- 读写分离 主从复制
- 机器学习之逐次下降法
- 111. Minimum Depth of Binary Tree
- svn的搭建安装和使用-简明教程
- 20个高效正则表达式
- 基于Skip-Gram的Word2Vec神经网络实现
- RegQueryValueExW errorcode=2
- Nginx基本配置、性能优化指南
- WebSocket介绍,与Socket的区别
- log4j日志记录
- 史上最简单的 SpringCloud 教程 | 终章