Skip to content

Instantly share code, notes, and snippets.

@piusayowale
Created August 21, 2022 14:37
Show Gist options
  • Save piusayowale/4f0616eb52ed680f21ac4d4184e315ec to your computer and use it in GitHub Desktop.
Save piusayowale/4f0616eb52ed680f21ac4d4184e315ec to your computer and use it in GitHub Desktop.
int lengthOfLongestSubstring(string s) {
set<char> cache;
int m = 0;
int count = 0;
for(int i = 0; i < s.size(); i++){
cache.clear();
cache.insert(s[i]);
count = 1;
for(int j = i + 1; j < s.size(); j++){
if(cache.insert(s[j]).second!= true){
break;
}else{
count++;
}
}
m = max(m, count);
}
return m;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment