Created
July 19, 2014 02:40
-
-
Save jingz8804/92f07e4b26d6b00db595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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