/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int minDepth(TreeNode root) {
return minDepthHelper(root, false);
}
private int minDepthHelper(TreeNode node, boolean hasBrother){
if(node == null)
return hasBrother?Integer.MAX_VALUE: 0;
return Math.min(minDepthHelper(node.left,node.right!=null),minDepthHelper(node.right, node.left!=null))+1;
}
}
----------------
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.
=========
hint:
递归的理解,最短路径停止的特征,没有兄弟