题解 | #二叉树的最小深度#

二叉树的最小深度

http://www.nowcoder.com/practice/e08819cfdeb34985a8de9c4e6562e724

public class Solution {
/**
*
* @param root TreeNode类
* @return int整型
*/
public int run (TreeNode root) {
// write code here
if(root == null) return 0;
return my(root,0);
}
public int my(TreeNode root, int count){
if(root == null) return count;
count++;
if(root.left==null&&root.right==null) return count;
else if (root.left==null) return my(root.right,count);
else if (root.right==null) return my(root.left,count);
else return Math.min(my(root.left,count),my(root.right,count));
}
}

全部评论

相关推荐

06-27 18:45
中山大学 Ruby
25届应届毕业生,来广州2个礼拜了,找不到工作,绝望了,太难过了…
应届想染班味:9爷找不到工作只能说明,太摆了或者太挑了。
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 Java
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
认真搞学习:28小登的建议,投算法岗不要写什么物理竞赛,互联网+,多写点项目,用什么算法做了什么。还有本科算法是不可能的开发你这个也没有项目啊
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 17:30
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务