Skip to content

Instantly share code, notes, and snippets.

@Chen-tao
Created February 8, 2017 09:25
Show Gist options
  • Save Chen-tao/edbfb476c54e199959e7c6ad42e39671 to your computer and use it in GitHub Desktop.
Save Chen-tao/edbfb476c54e199959e7c6ad42e39671 to your computer and use it in GitHub Desktop.
/**
* 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 maxDepth(TreeNode root) {
if(root == null) return 0;
int max = Math.max(maxDepth(root.left), maxDepth(root.right));
return max+1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment