LeetCode 22 Generate Parentheses

题目

class Solution {
public:
    int s[10005];
    vector res;
    vector generateParenthesis(int n) {
        
        if(n==0)
            return res;
        fun("",0,0,0,0,n);
        
        return res;
          
    }
    
    void fun(string str,int left,int right,int pos,int index,int n)
    {
       
        if(index==n*2)
        {
            res.push_back(str);
            return;
        }
        if(pos==0)
        {
            s[pos]=-1;
            fun(str+"(",left+1,right,pos+1,index+1,n);
        }
        else
        {
            if(s[pos-1]==-1)
            {
                s[pos]=-1;
                if(left

你可能感兴趣的:(LeetCode 22 Generate Parentheses)