diff --git a/Top150Interview/22_Generate_Parenthesis.py b/Top150Interview/22_Generate_Parenthesis.py index fc5f45a..b9f9201 100644 --- a/Top150Interview/22_Generate_Parenthesis.py +++ b/Top150Interview/22_Generate_Parenthesis.py @@ -1,7 +1,25 @@ -def generateParenthesis(n): +def generateParenthesis(n: int) -> List[str]: """ :type n: int :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) \ No newline at end of file