3. Longest Substring Without Repeating Characters
class Solution {
public:
int lengthOfLongestSubstring(string s) {
if(s.empty())
return 0;
int start=0,end=0,maxlen=0;
unordered_map<char,int> map;
for(int end=0;end<s.size();){
if(map.find(s[end])==map.end()){
map[s[end]]=end;
maxlen=max(end-start+1,maxlen);
end++;
}
else{
start=map[s[end]]+1;
end=start;
map.clear();
}
}
return maxlen;
}
};