-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ22.py
More file actions
22 lines (21 loc) · 750 Bytes
/
Q22.py
File metadata and controls
22 lines (21 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from typing import List
class Solution:
def generateParenthesis(self, n: int) -> List[str]:
S = set()
templist = [""]
for i in range(n):
size = len(templist)
for i in range(size):
valList = list(templist[i])
for i in range(len(valList)+1):
temp = valList[:]
temp.insert(i,"()")
resStr = "".join(temp)
if resStr not in templist:
templist.append("".join(temp))
templist = templist[size:]
for val in templist:
S.add(val)
return S
if __name__ == '__main__':
print(Solution().generateParenthesis(4))