Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fun(open,close,cur,ans):
- if open==0 and close==0:
- ans.add(cur)
- if open>0:
- fun(open-1,close,cur+'(',ans)
- if close>open:
- fun(open,close-1,cur+')',ans)
- class Solution:
- def generateParenthesis(self, n: int) -> List[str]:
- ans=set()
- fun(n,n,'',ans)
- return list(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement