题解 | #二叉树的最小深度#
二叉树的最小深度
http://www.nowcoder.com/practice/e08819cfdeb34985a8de9c4e6562e724
import java.util.*;
/*
* public class TreeNode {
* int val = 0;
* TreeNode left = null;
* TreeNode right = null;
* }
*/
public class Solution {
/**
*
* @param root TreeNode类
* @return int整型
*/
public int run (TreeNode root) {
// write code here
if(root==null){
return 0;
}
int left = run(root.left);
int right = run(root.right);
if(left*right >0){
return (left>right?right:left)+1;
}else{
return (left>right?left:right)+1;
}
}
}