Skip to content

Instantly share code, notes, and snippets.

@197291
Last active May 17, 2019 11:37
Show Gist options
  • Save 197291/2b6cbba06a8dd7429e06066c69bc7c57 to your computer and use it in GitHub Desktop.
Save 197291/2b6cbba06a8dd7429e06066c69bc7c57 to your computer and use it in GitHub Desktop.
var lengthOfLongestSubstring = function(s) {
let start = 0, maxLen = 0;
const map = new Map();
for(let i = 0; i < s.length; i++) {
const ch = s[i];
if(map.get(ch) >= start) start = map.get(ch) + 1;
map.set(ch, i);
if(i - start + 1 > maxLen) maxLen = i - start + 1;
}
return maxLen;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment