Created
October 12, 2016 21:43
-
-
Save Roger7410/92e2004fa9e3b17ce696c0d073187d7e 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
| /** | |
| * Definition for a binary tree node. | |
| * public class TreeNode { | |
| * int val; | |
| * TreeNode left; | |
| * TreeNode right; | |
| * TreeNode(int x) { val = x; } | |
| * } | |
| */ | |
| public class Solution { | |
| public int max = 0; | |
| public int count = 0; | |
| public int maxDepth(TreeNode root) { | |
| if(root != null){ | |
| count++; | |
| if (root.left == null && root.right == null) { | |
| if(count > max){ | |
| max = count; | |
| } | |
| } else { | |
| maxDepth(root.left); | |
| maxDepth(root.right); | |
| } | |
| count--; | |
| } | |
| return max; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment