backtrack
that takes the current string cur
, the count of left parentheses left
, and the count of right parentheses right
.2n
, add it to the result list as a valid combination.left
is less than n
, call backtrack
with an additional (
and increment left
.right
is less than left
, call backtrack
with an additional )
and increment right
.backtrack
with an empty string and counts set to 0.