This document contains code for a Solution class that defines a method called solution. The solution method calls another method called returnLength that recursively determines the length of a tree by finding the longest path from the root node to a leaf node. ReturnLength returns this length plus one, and solution simply returns this length minus one to find the number of nodes in the tree.
This document contains code for a Solution class that defines a method called solution. The solution method calls another method called returnLength that recursively determines the length of a tree by finding the longest path from the root node to a leaf node. ReturnLength returns this length plus one, and solution simply returns this length minus one to find the number of nodes in the tree.
This document contains code for a Solution class that defines a method called solution. The solution method calls another method called returnLength that recursively determines the length of a tree by finding the longest path from the root node to a leaf node. ReturnLength returns this length plus one, and solution simply returns this length minus one to find the number of nodes in the tree.
This document contains code for a Solution class that defines a method called solution. The solution method calls another method called returnLength that recursively determines the length of a tree by finding the longest path from the root node to a leaf node. ReturnLength returns this length plus one, and solution simply returns this length minus one to find the number of nodes in the tree.
// 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; } }