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; } };