Longest Substring Without Repeating Characters

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        string res="";
        int maxlen=0;
        for(int i=0;i<s.length();i++)
        {
            if(res.find(s[i])==res.npos)
            {
                res+=s[i];
                maxlen=(maxlen>res.length())?maxlen:res.length();
            }
            else
            {
                res.erase(0,res.find(s[i])+1);
                res+=s[i];
            }
        }
        return maxlen;
    }
};

  

原文地址:https://www.cnblogs.com/xlqtlhx/p/7862220.html