1 /** 2 * Definition for a binary tree node. 3 */ 4 public class TreeNode { 5 int val; 6 TreeNode left; 7 TreeNode right; 8 TreeNode(int x) { val = x; } 9 } 10 11 class Solution { 12 public int minDepth(TreeNode root) { 13 if(null == root){ 14 return 0; 15 } 16 if(root.left == null){ 17 return minDepth(root.right)+1; 18 } 19 if(root.right == null){ 20 return minDepth(root.left)+1; 21 } 22 return Math.min(minDepth(root.left), minDepth(root.right))+1; 23 24 } 25 }