← All problems

Generate Parentheses

medium

Given n pairs of parentheses, return all combinations of well-formed parenthesis strings, in any order.

Only add ( while you still have some left to place, and only add ) while fewer closes than opens have been placed so far — that constraint alone keeps every generated string balanced.

Example

Input: n = 1
Output: ["()"]
Loading...