Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gauravkr0071/b3cd4cdffcf66ec2fc7ef1b49b4d566a to your computer and use it in GitHub Desktop.
Save gauravkr0071/b3cd4cdffcf66ec2fc7ef1b49b4d566a to your computer and use it in GitHub Desktop.
Longest Substring Without Repeating 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