Created
December 12, 2017 20:43
-
-
Save aire-con-gas/fa865476bd0afdf6e2c63fb5b69565e9 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
| 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