<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>

#include<iostream>
#include<vector>

class Solution{
public:
    std::vector<std::string> generateParenthesis(int n){
        return generateParenthesis(n, '(', "", 0, 0);
    }

private:
    std::vector<std::string> generateParenthesis(int n, char choice, std::string str, int status, int total_open_par_count){
        std::vector<std::string> result = {};

        str += choice;
        if(choice == '('){
            total_open_par_count++;
            status++;
        }
        else{
            status--;
        }

        if(status == 0 && total_open_par_count == n){
            result.push_back(str);
            return result;
        }

        std::vector<std::string> set1, set2;

        if(total_open_par_count < n)
            set1 = generateParenthesis(n, '(', str, status, total_open_par_count);
        if(status > 0)
            set2 = generateParenthesis(n, ')', str, status, total_open_par_count);

        result.insert(result.end(), set1.begin(), set1.end());
        result.insert(result.end(), set2.begin(), set2.end());

        return result;
    }
};

23943