Skip to content

Instantly share code, notes, and snippets.

@InterviewBytes InterviewBytes/MaxDepth.java Secret
Created Jun 11, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.