Tree Height

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

// you can also use imports, for example:

// import java.util.*;

// you can write to stdout for debugging purposes, e.g.


// System.out.println("this is a debug message");

class Solution {

private int returnLenght(Tree T) {


int l = 0, r = 0;
if (T.l != null) {
l = returnLenght(T.l);
}
if (T.r != null) {
r = returnLenght(T.r);
}
if(r > l) {
return r + 1;
} else {
return l + 1;
}
}

public int solution(Tree T) {


int l = returnLenght(T);

return l - 1;
}
}

You might also like