Last active
July 28, 2020 03:48
-
-
Save hillal20/cbe4b1f6f33d131940e60aee605aef9d to your computer and use it in GitHub Desktop.
LongestSubstringWithNoRepeatedCharacters
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
let string = "abcfggedkhlysd"; | |
let splited = string.split(''); | |
let str2 = ""; | |
let str1 = "" ; | |
let str3 = ""; | |
const obj = {}; | |
for(let i = 0; i < splited.length ; i++){ | |
str1 += splited[i] | |
obj[splited[i]] = true; | |
obj[str1] = true; | |
for(let b = i+1 ;b < splited.length; b++){ | |
str2 = splited[i] + splited[b] ; | |
str3 += splited[b]; | |
obj[str2] = true; | |
obj[str3]= true; | |
} | |
str3=""; | |
} | |
console.log(Object.keys(obj)) | |
let log = ""; | |
let b = ""; | |
Object.keys(obj).forEach(e => { | |
if(e.length < log.length ) return; | |
e.split("").forEach(i => { | |
if(b.includes(i) === false) { | |
b+=i; | |
if(log.length < b.length ){ | |
log = b; | |
} | |
} | |
else b =""; | |
}) | |
b=""; | |
}); | |
console.log("====> ",log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment