n
is odd; if not, return an empty list since full binary trees require an odd number of nodes.n
is 1, return a list containing a single node tree.n
nodes is already computed, return it from the memoization map.res
to store the root nodes of all possible full binary trees with n
nodes.i
from 1 to n - 1
, and for each i
, do the following:
a. Recursively call the function to get all possible full binary trees with i
nodes for the left subtree.
b. Recursively call the function to get all possible full binary trees with n - i - 1
nodes for the right subtree.
c. For each combination of left and right subtrees, create a new tree with a root node and add it to res
.res
in the memoization map with key n
.res
.