/**
 *	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.
 *
 *	Author: matao
 *
 */


class TreeNode {
	int val;
	TreeNode left;
	TreeNode right;
	TreeNode(int x) { val = x; }
}

public class MinimumDepthOfBinaryTree {
	public int minDepth(TreeNode root) {
		if (root == null){
            return 0;
        }
        if (root.left == null && root.right == null){
            return 1;
        }
        int leftDepth = Integer.MAX_VALUE;
        if (root.left != null){
            leftDepth = minDepth(root.left) + 1 ;
        }
        int rightDepth = Integer.MAX_VALUE;
        if (root.right != null){
            rightDepth = minDepth(root.right) + 1;
        }
        
        return leftDepth < rightDepth ? leftDepth : rightDepth;
    }
}
@@ -336,16 +336,23 @@
 %09public 
+static 
 int minD
@@ -439,51 +439,119 @@
    i
-f (root.left == null && root.right == null)
+nt leftDepth = minDepth(root.left);%0A        int rightDepth = minDepth(root.right);%0A        if (leftDepth == 0) 
 %7B%0A  
@@ -566,16 +566,29 @@
   return
+ rightDepth +
  1;%0A    
@@ -602,30 +602,30 @@
        i
-nt lef
+f(righ
 tDepth =
  Integer
@@ -620,59 +620,48 @@
 th =
- Integer.MAX_VALUE;%0A        if (root.left != null)%7B
+= 0) %7B%0A            return leftDepth + 1;
 %0A   
@@ -669,102 +669,185 @@
     
+%7D%0A
     
-leftDepth = minDepth(root.left) + 1 ;%0A    
+    return leftDepth + 1 %3C rightDepth + 1 ? leftDepth + 1: rightDepth + 1;%0A
     %7D%0A
+%0A
     
-    int rightDepth = Integer.MAX_VALUE
+public static void main(String%5B%5D args) %7B%0A        TreeNode testTree1 = new TreeNode(1)
 ;%0A  
@@ -856,32 +856,83 @@
     
-if (roo
+System.ou
 t.
+p
 ri
-ght !
+ntln(minDepth(testTree1));%0A        TreeNode testTree2 
 = null
-)%7B
+;
 %0A   
@@ -940,132 +940,184 @@
     
-    rightDepth = minDepth(root.right) + 1;%0A        %7D%0A        %0A        return leftDepth %3C rightDepth ? leftDepth : rightDepth
+System.out.println(minDepth(testTree2));%0A        TreeNode testTree3 = new TreeNode(1);%0A        testTree3.left = new TreeNode(2);%0A        System.out.println(minDepth(testTree3))
 ;%0A  

add Minimum Depth Of Binary Tree solution