The TransCompilator

Solved LeetCode program · 22 of 1,000

#0022 · Generate Parentheses

Medium String chunk-01.md

Original English source

Keep a shared current as empty text. Keep a shared answers as an empty list of text. Keep a shared copy as empty text.
To build from opened (a whole number) with closed (a whole number). If opened plus closed is 6, The copy is a copy of current, Place copy into answers, then return. If opened is less than 3, Place "(" into current, build from opened plus 1 with closed, remove last character from current. If closed is less than opened, Place ")" into current, build from opened with closed plus 1, remove last character from current.

Build from 0 with 0. For each answer in answers, display answer.

Open in Playground Browse all 1,000 problems

Expected stdout

((()))
(()())
(())()
()(())
()()()