Longest Substring Without Repeat Characters
1 var lengthOfLongestSubstring = function(s) { 2 if (s === '') { 3 return 0; 4 } 5 6 var lenMax = 1, 7 lenCurr = 1, 8 i, repeat; 9 10 for (i = 1; i < s.length; i++) { 11 repeat = s.substr(i - lenCurr, lenCurr).indexOf(s.substr(i, 1)); 12 13 if (repeat == -1) { 14 lenCurr++; 15 } else { 16 lenCurr -= repeat; 17 } 18 19 if (lenCurr > lenMax) { 20 lenMax = lenCurr; 21 } 22 } 23 24 return lenMax; 25 };