Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
"((()))", "(()())", "(())()", "()(())", "()()()"
class Solution {
public:
void process(int left, int right,string str,vector<string>& result){
if(left == 0 && right == 0){
result.push_back(str);
}
if(right > 0 && right <= left){
process(left, right - 1, str + "(", result);
}
if(left > 0){
process(left - 1, right, str + ")", result);
}
}
vector<string> generateParenthesis(int n) {
vector<string>result;
process(n,n,"",result);
return result;
}
};