Get unlimited access
Open in app
Home
Notifications
Lists
Stories

Write
Steven Lu
Steven Lu

Jan 7

·
1 min read

LeetCode — Unique Binary Search Trees

Given an integer n, return all the structurally unique BST's (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order.

Example 1:

Input: n = 3
Output: [[1,null,2,null,3],[1,null,3,2],[2,1,3],[3,1,null,null,2],[3,2,null,1]]

Example 2:

Input: n = 1
Output: [[1]]

Constraints:

  • 1 <= n <= 8

Solution:

--

--

More from Steven Lu

👨‍💻

Love podcasts or audiobooks? Learn on the go with our new app.

Try Knowable

Recommended from Medium

Shahab Khan

Shahab Khan

[FREE MODULE] PrestaShop Popup — Colorbox on All Pages

Ganesa Vijayakumar

Ganesa Vijayakumar

𝗟𝗶𝘀𝘁 𝗼𝗳 𝗳𝗿𝗲𝗲 𝘄𝗲𝗯𝘀𝗶𝘁𝗲 𝗵𝗼𝘀𝘁𝗶𝗻𝗴 𝘀𝗲𝗿𝘃𝗶𝗰𝗲𝘀

Phillipp

Phillipp

in

Ultimate SGC

DevBlog 1: User Authentication

Surabhi C.

Surabhi C.

Custom Software Development — The Easy Way to Expand Business

Max Patrick

Max Patrick

CS373 Spring 2020: Max Patrick

Charlie Fay

Charlie Fay

Essential Tools For the SFMC Practitioner

jerome.decoster

jerome.decoster

CDK + CDKTF + Lambda + DynamoDB

Monday Maps

Monday Maps

Creating a Route Map with Offsets

AboutHelpTermsPrivacy


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Steven Lu

Steven Lu

👨‍💻

More from Medium

Pakshal Jain

Pakshal Jain

Leetcode Q#217-Contains Duplicate

Diary of an Indian Programmer

Diary of an Indian Programmer

LeetCode — Day 1: Question 2

yoshie

yoshie

Leetcode — anagram

Luis Escobar

Luis Escobar

Leetcode 169: Majority Element

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Knowable