题解 | #括号生成#
括号生成
https://www.nowcoder.com/practice/c9addb265cdf4cdd92c092c655d164ca
void recursion(int left,int right,string temp,vector<string> &res,int n) { if (left == n && right == n) { res.push_back(temp); return; } if (left < n) { recursion(left + 1, right, temp + "(", res, n); } if (right < n && left > right) { recursion(left, right + 1, temp + ")", res, n); } } vector<string> generateParenthesis(int n) { vector<string> res; string temp; recursion(0, 0, temp, res, n); return res; }