Unique Binary Search Trees II

Given an integer n, return all structurally unique binary search trees (BSTs) that have exactly n nodes with distinct values from 1 to n, in any order.

Each tree is transported as its preorder traversal, a list of node values in the order a preorder walk visits them. For a BST, the preorder traversal uniquely determines the tree, so this encoding is lossless. The outer list contains one preorder list per distinct tree; the order of that outer list does not matter.

Examples
Input: 1
Output: [[1]]
Hints

Unique Binary Search Trees II

Given an integer `n`, return all structurally unique binary search trees (BSTs) that have exactly `n` nodes with distinct values from `1` to `n`, in any order.