Skip to content

Instantly share code, notes, and snippets.

@aire-con-gas
Created December 12, 2017 20:43
Show Gist options
  • Select an option

  • Save aire-con-gas/fa865476bd0afdf6e2c63fb5b69565e9 to your computer and use it in GitHub Desktop.

Select an option

Save aire-con-gas/fa865476bd0afdf6e2c63fb5b69565e9 to your computer and use it in GitHub Desktop.
const longestSubstrLen = (s) => {
const originalStrLen = s.length;
const originalStrArr = s.split('');
let subStrLen = 0;
const lookupMap = {};
for(let j=0, i=0; j < originalStrLen; j++) {
const currChar = originalStrArr[j];
console.log('i', i);
console.log('j', j);
console.log('currChar at j', currChar);
console.log('lookupMap[currChar]', lookupMap[currChar]);
if (lookupMap[currChar]) {
i = Math.max(lookupMap[currChar], i);
}
subStrLen = Math.max(subStrLen, j-i + 1);
lookupMap[currChar] = j + 1;
}
return subStrLen;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment