static int x=[](){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}();
class Solution {
public:
vector<string> generateParenthesis(int n) {
vector<string> res;
generateParenthesis(res, "", n, n);
return res;
}
void generateParenthesis(vector<string>& res, string temp, int left, int right){
if (left > right)
return;
if (left <= 0 && right <= 0){
res.push_back(temp);
return;
}
if (left > 0)generateParenthesis(res, temp + '(', left - 1, right);
if (right> 0)generateParenthesis(res, temp + ')', left, right - 1);
}
};
LetCode 22. 括号生成
最新推荐文章于 2025-04-01 21:06:01 发布