码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode#111 Minimum Depth of Binary Tree

时间:2015-02-02 12:30:43      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:

原题地址

 

基本二叉树遍历

 

代码:

1 int minDepth(TreeNode *root) {
2         if (!root)
3             return 0;
4             
5         int l = root->left ? minDepth(root->left) : 0;
6         int r = root->right ? minDepth(root->right) : 0;
7         
8         return l * r > 0 ? min(l, r) + 1 : max(l, r) + 1;
9 }

 

Leetcode#111 Minimum Depth of Binary Tree

标签:

原文地址:http://www.cnblogs.com/boring09/p/4267439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!