first attempt at generate strings, need filter for permutations
This commit is contained in:
parent
571fd5d3d2
commit
756a6a01cc
@ -1,7 +1,25 @@
|
|||||||
def generateParenthesis(n):
|
def generateParenthesis(n: int) -> List[str]:
|
||||||
"""
|
"""
|
||||||
:type n: int
|
:type n: int
|
||||||
:rtype: List[str]
|
:rtype: List[str]
|
||||||
"""
|
"""
|
||||||
|
stack = []
|
||||||
|
pairs = ""
|
||||||
|
opening_brackets = {'('}
|
||||||
|
closing_brackets = {')'}
|
||||||
|
bracket_pairs = {')': '('}
|
||||||
|
|
||||||
|
# Create n pairs
|
||||||
|
for i in range(n):
|
||||||
|
pairs += "()"
|
||||||
|
# print(pairs)
|
||||||
|
|
||||||
|
# Create and filter permutations
|
||||||
|
for pair in permutations(pairs):
|
||||||
|
parenthesis = "".join(pair)
|
||||||
|
# print(pair)
|
||||||
|
# print(parenthesis)
|
||||||
|
if parenthesis in bracket_pairs.keys():
|
||||||
|
if not stack or stack[-1] != bracket_pairs[parenthesis]:
|
||||||
|
print('bad')
|
||||||
generateParenthesis(3)
|
generateParenthesis(3)
|
||||||
Loading…
Reference in New Issue
Block a user