Question
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
Example 1:
Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"]
Example 2:
Input: n = 1 Output: ["()"]
Constraints:
1 <= n <= 8
Python Solution
class Solution:
def generateParenthesis(self, n: int) -> List[str]:
if n==0:
return []
return self.rec(n,'',0,0,[])
def rec(self,n,s,opened,closed,result):
if opened==n and closed!=n:
result.append((s + ')'*(n-closed)))
elif opened==closed and opened<=n:
self.rec(n,s+'(',opened+1,closed,result)
elif opened > closed and opened<=n:
self.rec(n,s+')',opened,closed+1,result)
if opened<n:
self.rec(n,s+'(',opened+1,closed,result)
return result

![[Solved] You are given an integer n and an integer start. Define an array nums where nums[i] = start + 2 * i (0-indexed) and n == nums.length. Return the bitwise XOR of all elements of nums.](https://machinelearningprojects.net/wp-content/uploads/2022/09/Leetcode-solutions-MLP-Feature-Image-1024x536.webp)