Created
October 12, 2016 21:49
-
-
Save Roger7410/1a20033556caf94d6c6523405847ae6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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