国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

LeetCode 22. Generate Parentheses

2019-11-08 03:16:49
字體:
供稿:網(wǎng)友

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:

[  "((()))",  "(()())",  "(())()",  "()(())",  "()()()"]

answer:

class Solution {public:    vector<string> generateParenthesis(int n) {        vector<string> result;        string str = "";        addPar(result,str,n,0);        return result;    }        void addPar(vector<string> & result, string str, int left, int right){        if(left == 0 && right == 0){            result.push_back(str);            return;        }        if(left > 0){            addPar(result, str + "(", left - 1, right + 1);        }        if(right > 0){            addPar(result, str + ")", left, right - 1);        }    }};


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 石泉县| 满城县| 绩溪县| 襄城县| 龙门县| 灵宝市| 台东市| 奈曼旗| 中方县| 桃园县| 喀喇沁旗| 栾川县| 陆良县| 江孜县| 大兴区| 铜山县| 六安市| 南城县| 英德市| 南通市| 精河县| 灵川县| 千阳县| 温州市| 萨嘎县| 米泉市| 兰坪| 泊头市| 洛阳市| 昌邑市| 吉隆县| 嘉禾县| 洪雅县| 库车县| 吉隆县| 丽水市| 曲麻莱县| 新宁县| 涿州市| 修文县| 西藏|