Skip to content

Instantly share code, notes, and snippets.

@InterviewBytes
Created June 11, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InterviewBytes/0ad6919d5e233b1e9f503e882275b09b to your computer and use it in GitHub Desktop.
Save InterviewBytes/0ad6919d5e233b1e9f503e882275b09b to your computer and use it in GitHub Desktop.
MaxDepth tree
package com.interviewbytes.trees;
public class MaxDepth {
public int maxDepth(TreeNode root) {
if (root == null) return 0;
return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
}
}
package com.interviewbytes.trees;
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) {
val = x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment