题目:https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
代码:
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int maxlen =0,pos=-1;
map<char,int> t;
for(int i =0;i<s.length();i++){
if(t.count(s[i])!=0){
pos = max(pos,t[s[i]]);
}
t[s[i]] = i;
maxlen = max(maxlen,i-pos);
}
return maxlen;
}
};