Last active
May 17, 2019 11:37
-
-
Save 197291/2b6cbba06a8dd7429e06066c69bc7c57 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
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