Created
May 13, 2014 14:28
-
-
Save Cee/0d85d28c4f0893238700 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 binary tree | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { | |
public int maxDepth(TreeNode root) { | |
if (root == null){ | |
return 0; | |
} else { | |
int left = maxDepth(root.left); | |
int right = maxDepth(root.right); | |
int ret; | |
if (left > right){ | |
ret = left + 1; | |
} else { | |
ret = right + 1; | |
} | |
return ret; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment