Skip to content

Instantly share code, notes, and snippets.

@Roger7410
Created October 12, 2016 21:49
Show Gist options
  • Select an option

  • Save Roger7410/1a20033556caf94d6c6523405847ae6f to your computer and use it in GitHub Desktop.

Select an option

Save Roger7410/1a20033556caf94d6c6523405847ae6f to your computer and use it in GitHub Desktop.
public class Solution {
int min = Integer.MAX_VALUE;
int count = 0;
public int minDepth(TreeNode root) {
if(root!=null){
count++;
if(root.left==null && root.right==null){
if(count < min) min = count;
}else{
minDepth(root.left);
minDepth(root.right);
}
count--;
}else{
return 0;
}
return min;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment