<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:
    void helper(int o,int c,int n,vector<string>&ans,string temp){
        if(o<0||c<0){
            return;
        }
        if(o==0&&c==0){
            ans.push_back(temp);
        }else{
            //cout<<temp<<endl;
            string temp1=temp;
            temp1+='(';
            helper(o-1,c,n,ans,temp1);
            if(c>o){
                string temp2=temp;
                temp2+=')';
                helper(o,c-1,n,ans,temp2);
            }
            return;
        }
    }
    vector<string> generateParenthesis(int n) {
        //o 3 // c 3 
        //keep reducing open 
        //if c>open fill close 
        vector<string>ans;
        helper(n,n,n,ans,"");
        return ans;
    }
};
17260