Skip to content

Instantly share code, notes, and snippets.

@hillal20
Last active July 28, 2020 03:48
Show Gist options
  • Save hillal20/cbe4b1f6f33d131940e60aee605aef9d to your computer and use it in GitHub Desktop.
Save hillal20/cbe4b1f6f33d131940e60aee605aef9d to your computer and use it in GitHub Desktop.
LongestSubstringWithNoRepeatedCharacters
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