My code was wrong, but get accepted, why?


  • 0
    L
    vector<string> generateParenthesis(int n) {
        vector<string> ret;
        if(n == 0)
            return ret;
        set<string> st1, st2;
        st1.insert("()");
        for(int i = 2; i <= n; ++i)
        {
            for(set<string>::iterator it = st1.begin(); it != st1.end(); ++it)
            {
                string ss = *it;
                for(int j = 1; j < ss.length(); ++j)
                {
                    st2.insert("()" + ss);
                    for(int k = j; k < ss.length(); ++k)
                    {
                        string x = ss.substr(0, j) + "(" + ss.substr(j, k-j) + ")" + ss.substr(k);
                        st2.insert(x);
                    }
                    st2.insert(ss + "()");
                }
            }
            st1.swap(st2);
            st2.clear();
        }
        ret.insert(ret.begin(), st1.begin(), st1.end());
        sort(ret.begin(), ret.end());
    }
    

    this is my code, in the end I forgot "return ret", but after submit my code, it's still accepted, why is that?


Log in to reply
 

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