
public class MinimumDepthofBinaryTree {
	
	public int minDepth(TreeNode root) {
        if(root == null)
        	return 0;
        if(root.left == null && root.right != null){
        	return minDepth(root.right)+1;
        }
        if(root.right == null && root.left != null){
        	return minDepth(root.left)+1;
        }
        return minDepth(root.left) <= minDepth(root.right) ? minDepth(root.left)+1 : minDepth(root.right)+1;  
    }
	
	public static void main(String[] args){
		MinimumDepthofBinaryTree test = new MinimumDepthofBinaryTree();
		TreeNode root = new TreeNode(1);
		root .left = new TreeNode(1);
		root.left.left = new TreeNode(1);
		System.out.print(test.minDepth(root));
	}
}
