<p>Given an integer <code>n</code>, return <em>a list of all possible <strong>full binary trees</strong> with</em> <code>n</code> <em>nodes</em>. Each node of each tree in the answer must have <code>Node.val == 0</code>.</p>

<p>Each element of the answer is the root node of one possible tree. You may return the final list of trees in <strong>any order</strong>.</p>

<p>A <strong>full binary tree</strong> is a binary tree where each node has exactly <code>0</code> or <code>2</code> children.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/08/22/fivetrees.png" style="width: 700px; height: 400px;" />
<pre>
<strong>Input:</strong> n = 7
<strong>Output:</strong> [[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 3
<strong>Output:</strong> [[0,0,0]]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 20</code></li>
</ul>

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def allPossibleFBT(self, n: int) -> List[Optional[TreeNode]]:
        """
        n = 0 -> []
        n = 1 -> 1
        n = 2 -> []
        n = 3 -> 1
                / \
               2   3
        n = 4 -> []
        n = 5 ->  1          1
                 / \        / \
                2   3      2   3
               / \            / \
              4   5          4   5
        
        n = 6 -> []
        n = 7: left
        """
        if n % 2 == 0:
            return []
        
        if n == 1:
            return [TreeNode(0)]
        
        res = []
        
        # Now n = 2k+1 and n >= 3
        root = TreeNode(0)
        
        for k in range(1, n - 1, 2):
            subtrees_A = self.allPossibleFBT(k)
            subtrees_B = self.allPossibleFBT(n - 1 - k)
            for subtree_A in subtrees_A:
                for subtree_B in subtrees_B:
                    root.left = subtree_A
                    root.right = subtree_B
                    res.append(copy.copy(root))
                
        return res
26400