3. 无重复字符的最长子串

class Solution {
public:
    int lengthOfLongestSubstring(string s) {

        int res=0,rul=1;
        map <char, int> word;
        for(int i=1;i<=s.length();++i){
            if(word[s[i-1]]>=rul){
                rul=word[s[i-1]]+1;
                word[s[i-1]]=i; 
            }else{
                word[s[i-1]]=i;
                res = max(res,i-rul+1);
            }
        }
        return res;
    }
};
原文地址:https://www.cnblogs.com/cattree/p/13019149.html