The judgement of this question has a bug! if the result is presented in a different order, it is wrong.


  • -5

    class Solution {
    public:
    vector<string> generateParenthesis(int n)
    {
    vector<string> result;
    vector<string> s;
    if(n==0)
    return result;
    else if(n==1)
    {
    result.push_back("()");
    return result;
    }
    else
    {
    s=generateParenthesis(n-1);
    for(int i=0; i<s.size(); i++)
    result.push_back("("+s[i]+")");
    for(i=0; i<s.size(); i++)
    {
    result.push_back(s[i]+"()");
    if("()"+s[i]!=s[i]+"()")
    result.push_back("()"+s[i]);
    }
    return result;
    }
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.