2
def generateParenthesis(self, n: int) -> list[str]:4
# Initialize the result7
# Recursively go through all possible combinations8
def add(open, close, partialRes):12
# If we have added opening and closing parentheses n times, we reaches a solution13
if open == close == n:14
res.append("".join(partialRes))17
# Add a closing parenthesis to the partial result if we have at least 1 opening parenthesis19
add(open, close + 1, partialRes + [")"])21
# Add an opening parenthesis to the partial result if we haven't added n parenthesis yet23
add(open + 1, close, partialRes + ["("])