首页 > 其他 > 详细

minimum depth of binary tree

时间:2017-02-19 19:54:51      阅读:160      评论:0      收藏:0      [点我收藏+]
1 /*Given a binary tree, find its minimum depth.The minimum depth is the number of nodes
2     along the shortest path from the root node down to the nearest leaf node.*/
3     int minDepth(TreeNode *root)
4     {
5         if(root == NULL) return 0;        
6         if (root->left==NULL) return 1 + minDepth(root->right);
7         if (root->right == NULL) return 1 + minDepth(root->left);
8         return 1 + min(minDepth(root->left), minDepth(root->right));        
9     }

 

minimum depth of binary tree

原文:http://www.cnblogs.com/hellowooorld/p/6416522.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!