Skip to main content
LeetCode 894, Medium. Topics: Dynamic Programming, Tree, Recursion, Memoization, Binary Tree. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 12 parametrized pytest cases, and a playground notebook:

Problem

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>

Examples

Constraints

  • 1 <= n <= 20

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026