Created
August 21, 2022 14:37
-
-
Save piusayowale/4f0616eb52ed680f21ac4d4184e315ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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