Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- static int height=-1;
- public int solution(Tree T) {
- if (T == null) return height;
- height = heightOfTree(T);
- return height;
- }
- public int heightOfTree(Tree node) {
- if (node != null) {
- if (node.l == null) {
- return heightOfTree(node.r);
- }
- if (node.r == null) {
- return 1 + heightOfTree(node.l);
- } else {
- return 1 + Math.max(heightOfTree(node.r), heightOfTree(node.l));
- }
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement