<p>Given <code>n</code> pairs of parentheses, write a function to <em>generate all combinations of well-formed parentheses</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> n = 3
<strong>Output:</strong> ["((()))","(()())","(())()","()(())","()()()"]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> n = 1
<strong>Output:</strong> ["()"]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 8</code></li>
</ul>

class Solution {
public:
    vector<string> generateParenthesis(int n) {
        vector<string> result;
        vector<char> current_combination;
        current_combination.reserve(2 * n);
        GenerateParenthesisHelper(0, 0, n, current_combination, result);
        return result;
    }

private:
    void GenerateParenthesisHelper(int open_count, int close_count, int n,
                                   vector<char>& current_combination,
                                   vector<string>& result) {
        if (open_count == n && close_count == n) {
            result.emplace_back(current_combination.begin(), current_combination.end());
            return;
        }
        if (open_count < n) {
            current_combination.push_back('(');
            GenerateParenthesisHelper(open_count + 1, close_count, n,
                                      current_combination, result);
            current_combination.pop_back();
        }
        if (close_count < open_count) {
            current_combination.push_back(')');
            GenerateParenthesisHelper(open_count, close_count + 1, n,
                                      current_combination, result);
            current_combination.pop_back();
        }
    }
};
13008