Skip to content

Instantly share code, notes, and snippets.

@jingz8804
Created July 19, 2014 02:40
Show Gist options
  • Save jingz8804/92f07e4b26d6b00db595 to your computer and use it in GitHub Desktop.
Save jingz8804/92f07e4b26d6b00db595 to your computer and use it in GitHub Desktop.
// Suppose we have a Node class that representing the node in the BT
// public class Node{
// int val;
// Node left;
// Node right;
// }
public class HeightOfBT{
private int height;
public int getHeight(Node root){
height = 0;
traverse(root, 0);
return height;
}
private void traverse(Node root, int level){
if(root == null) return;
if(level > height) height = level;
traverse(root.left, level + 1);
traverse(root.right, level + 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment