Please help me run the code, I run it correctly but leetcode dose not


  • 0
    D

    Leetcode shows runtime error when using the test case "bb", but I run from my laptop the test case
    just correct, it shows [["b","b"],["bb"]]

    Sorry for the format, I can not handle the format correctly, maybe you could copy the code to your
    text editor

    #include<queue>
    #include<set>
    #include<string>
    #include<iostream>
    #include<cstring>
    using namespace std;
    const int MAXN_M=1000;
    bool vis[MAXN_M][MAXN_M];
    class Solution {
    private:
    queue<vector<string> > q;
    public:
    vector<vector<string> > partition(string s) {
    memset(vis,0,sizeof(vis));
    //set<vector<string> > res;
    vector<vector<string> > res;
    vector<string> cur;
    for(int i=0;i<s.size();++i)
    {
    cur.push_back(string(1,s[i]));
    }
    q.push(cur);
    while(!q.empty())
    {
    cur=q.front();
    q.pop();
    //res.insert(cur);
    res.push_back(cur);
    bool firstEnter=true;
    int len=0;
    for(vector<string>::iterator itr=cur.begin();itr!=cur.end();++itr)
    {
    if(firstEnter)
    {
    firstEnter=false;
    continue;
    }
    else
    {
    int lens=len-(itr-1)->size();
    int len1e=len+itr->size();
    int len2e;
    if(itr!=(cur.end()-1))
    {
    len2e=len1e+(itr+1)->size();
    }

                    if((!vis[lens-1][len1e-1])&&(*itr==*(itr-1)))
                    {
                        vis[lens-1][len1e-1]=true;
                        vector<string> n(cur.begin(),itr-1);
                        string newItem=*(itr-1)+*itr;
                        n.push_back(newItem);
                        n.insert(n.end(),itr+1,cur.end());
                        q.push(n);
                    }
                    if((itr!=(cur.end()-1))&&(!vis[lens-1][len2e-1])&&(*(itr-1)==*(itr+1)))
                    {
                        vis[lens-1][len2e-1]=true;
                        vector<string> n(cur.begin(),itr-1);
                        string newItem=*(itr-1)+*itr+*(itr+1);
                        n.push_back(newItem);
                        if((itr+2)!=cur.end())
                        {
                            n.insert(n.end(),itr+2,cur.end());
                        }
                        q.push(n);
                    }
                }
                len+=itr->size();
            }
        }
        //return vector<vector<string> >(res.begin(),res.end());
        return res;
    }
    

    };
    int main()
    {
    Solution s;
    string str="bb";
    vector<vector<string> > res=s.partition(str);
    cout<<res.size()<<endl;
    for(vector<vector<string> >::iterator itr=res.begin();itr!=res.end();++itr)
    {
    for(vector<string>::iterator itr2=itr->begin();itr2!=itr->end();++itr2)
    {
    cout<<*itr2+" ";
    }
    cout<<endl;
    }
    return 0;
    }


  • 0
    H

    尼玛!!!!!!!!!!!!!!你这让人怎么看!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Log in to reply
 

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