LeetCode题目:Generate Parentheses

原题地址:https://leetcode.com/problems/generate-parentheses/

解决方法:回溯法

class Solution {
private:
    vector<string> coll;
    void helper(string s, int left, int right){
        if(left > right || left < 0 || right < 0)
            return;
        if(0 == left && 0 == right){
            coll.push_back(s);
            return;
        }
        string lString = s, rString = s;
        helper(lString += '(', left - 1, right);
        helper(rString += ')', left, right - 1);
    }
public:
    vector<string> generateParenthesis(int n) {
        string s;
        helper(s, n, n);
        return coll;
    }
};
原文地址:https://www.cnblogs.com/runnyu/p/5253065.html