Coding test/programmers - single
[leetcode] 22. Generate Parentheses
engine
2022. 3. 29. 11:52
class Solution:
def generateParenthesis(self, n: int) -> List[str]:
'''
type n = int
'''
self.res = []
self.helper("",n,n)
return self.res
def helper(self, current,left, right) :
if right == 0:
self.res.append(current)
else :
if left > 0:
self.helper(current + "(", left-1, right)
if left < right :
self.helper(current + ")", left, right-1)