The depth of a node is the number of edges from root to that node, right? But how to find it by a method like findDepth(Node node) in java?
2 Answers
So, based on this answer, already on stackOverflow, you can do this:
int findDepth(Node node) {
if (aNode == null) {
return -1;
}
int lefth = findHeight(node.left);
int righth = findHeight(node.right);
if (lefth > righth) {
return lefth + 1;
} else {
return righth + 1;
}
}