Longest Substring Without Repeating Characters help!!
Anonymous User
203

This is my code for this problem but this will not giving right answer when there is special character . help me to find the error in my code : )

bool uni(string s)
    {
        set<char> ss(s.begin(),s.end());
        return ss.size()==s.size();
    }
    
    int lengthOfLongestSubstring(string s) 
    {
        int m=0;  
        for(int i=0;i<s.length();i++)
        {
            for(int j=i+1;j<=s.length();j++)
            {
                string x=s.substr(i,j);
                if(uni(x))
                {
                    if(m<x.length())
                    {
                        m=x.length();
                    }
                }
                
            }
        }
        
        return m;
    }

image

Comments (1)