Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 13, 2014 14:28
Show Gist options
  • Save Cee/0d85d28c4f0893238700 to your computer and use it in GitHub Desktop.
Save Cee/0d85d28c4f0893238700 to your computer and use it in GitHub Desktop.
/**
* 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