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

Problem

Given an integer n, return the number of structurally unique BST’s (binary search trees) which has exactly n nodes of unique values from 1 to n.

Examples

Example 1

Constraints

  • 1 <= n <= 19

Solution

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

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026