MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / generateParenthesis

Method generateParenthesis

Backtracking/GenerateParentheses.py:26–46  ·  view source on GitHub ↗

:type n: int :rtype: List[str]

(self, n)

Source from the content-addressed store, hash-verified

24"""
25class Solution(object):
26 def generateParenthesis(self, n):
27 """
28 :type n: int
29 :rtype: List[str]
30 """
31 result = []
32
33 def _generateParenthesis(x, y, parenthesis):
34 if not x and not y:
35 result.append(parenthesis)
36 return
37
38 if y > x:
39 _generateParenthesis(x, y-1, parenthesis=parenthesis+')')
40
41 if x:
42 _generateParenthesis(x-1, y, parenthesis=parenthesis+'(')
43
44 _generateParenthesis(n-1, n, '(')
45
46 return result
47

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected