22. Generate Parentheses

来源:互联网 发布:nginx 反向代理 路径 编辑:程序博客网 时间:2024/06/16 10:50
void help(vector<string> &res,string s,int left, int right) {    {        if (right == 0) {            res.push_back(s);            return;        }        if (left) help(res, s + "(", left-1, right);        if(right>left) help(res, s + ")", left, right-1);    }}vector<string> generateParenthesis(int n) {    vector<string> res;    string s = "";    help(res, s, n, n);    return res;}

0 0
原创粉丝点击