class Solution { public: /** * @param s: a string * @return: an integer */ int lengthOfLongestSubstring(string s) { // write your code here if(0==s.size()) return 0; if(1==s.size()) return 1; map<char,int> check; int max=INT_MIN,size=s.size(),count=0; int i=0; while(i<size){ if(check[s[i]]){ i=check[s[i]]; check.clear(); if(count>max) max=count; count=0; }else{ check[s[i]]=i+1; ++i; ++count; } } return max>count?max:count; } };