C++ no map and vector


  • 0
    Z
    string str;
    int lon=0;
    int alll=0,allll=0;
    bool flag=false;
    for (int i=0;i<s.length();i++)
    {
    	if(flag)
    	{
    		str="";
    		for(int m=0;m<allll-alll;m++)
    		{
    			str.push_back(s[i-allll+alll+m]);
    		}
    		flag=false;
    	}
    	if (str.length()==0)
    	{
    		str.push_back(s[i]);
    	} 
    	else
    	{
    		for (int j=0;j<str.length();j++)
    		{
    			if (s[i]==str[j])
    			{
    				flag=true;
    				alll=j;
    				allll=str.length();
    				break;
    			} 
    			if (j==str.length()-1)
    			{
    				str.push_back(s[i]);
    				break;
    			}
    		}
    	}
    
    	if (lon<str.length())
    	{
    		lon=str.length();
    	}
    }
    return lon;

Log in to reply
 

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