forked from lazzzis/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
25 lines (22 loc) · 641 Bytes
/
Copy pathmain.py
File metadata and controls
25 lines (22 loc) · 641 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution(object):
def generateParenthesis(self, n):
"""
:type n: int
:rtype: List[str]
"""
def dfs(current, lst, left, right, n):
if left == right and len(current) == 2 * n:
lst.append(current)
return
if left < n:
dfs(current + '(', lst, left + 1, right, n)
if left > right:
dfs(current + ')', lst, left, right + 1, n)
ans = []
dfs('', ans, 0, 0, n)
return ans
import os
if os.getenv('LZS'):
# local test
s = Solution()
print(s.generateParenthesis(3))