头像

奔跑中的小新


访客:32

离线:3天前



class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        map<char,int>ss;
        int max_len = 0;
        for(int j = 0; j < s.size(); j++){
            int left = 0;
            if(ss.find(s[j]) != ss.end()){
                left = ss[s[j]] + 1;
            }
            int cur_len = j - left + 1;
            if(max_len < cur_len)
                max_len = cur_len;
            if(ss.find(s[j]) != ss.end())
                ss.erase(s[j]);
            ss[s[j]] = j;
        }
        return max_len;
    }
}