Created
August 6, 2021 09:09
-
-
Save gauravkr0071/b3cd4cdffcf66ec2fc7ef1b49b4d566a to your computer and use it in GitHub Desktop.
Longest Substring Without Repeating Characters
This file contains 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) { | |
vector<int> map(128,0); | |
int counter=0, begin=0, end=0, d=0; | |
while(end<s.size()){ | |
if(map[s[end++]]++>0) counter++; | |
while(counter>0) if(map[s[begin++]]-->1) counter--; | |
d=max(d, end-begin); //while valid, update d | |
} | |
return d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment