forked from shichao-an/leetcode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
17 lines (16 loc) · 485 Bytes
/
solution.py
File metadata and controls
17 lines (16 loc) · 485 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution:
# @param an integer
# @return a list of string
def generateParenthesis(self, n):
res = []
cand = ''
self.gp(n, n, cand, res)
return res
def gp(self, left, right, cand, res):
if left > right or left < 0:
return
elif left == 0 and right == 0:
res.append(cand)
else:
self.gp(left - 1, right, cand + '(', res)
self.gp(left, right - 1, cand + ')', res)