Created
August 23, 2020 18:54
-
-
Save gesslar/134a6419788f3df07aac34b2d0c1c81a to your computer and use it in GitHub Desktop.
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
/** | |
* @param {string} s | |
* @return {number} | |
*/ | |
const lengthOfLongestSubstring = s => { | |
let begin = 0 | |
let end = 1 | |
let final = "" | |
const length = s.length + 1 | |
while(begin < length && end < length) { | |
const sub = s.slice(begin, end) | |
const sublen = sub.length | |
const test = sub.slice(0, sublen - 1) | |
const last = sub.slice(sublen - 1) | |
if(test.indexOf(last) > -1 ) { | |
begin++ | |
} else { | |
if(sub.length > final.length) final = sub | |
end++ | |
} | |
} | |
return final.length | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment