var lengthOfLongestSubstring = function(s) {
var start = 0,longest = 0;
var offset = "a".charCodeAt(0);
var hash = new Array(26);
var stringLength = s.length;
for(i = 0; i < stringLength; i++){
if(stringLength  start <= longest){
break;
}
var char = s.charCodeAt(i);
var previousIndex = hash[char  offset];
if(!isNaN(previousIndex)){
if(previousIndex >= start) {
start = previousIndex + 1;
}
}
var currentLength = (i  start) + 1;
hash[char  offset] = i;
if(currentLength > longest){
longest = currentLength;
}
}
return longest;
};
Javascript solution using "pointers", beat 100%


Nice code. My answer wasn't as efficient as yours, but I cleaned it up to be functionally identical.
/** * @param {string} s * @return {number} */ var lengthOfLongestSubstring = function(s) { var positions = {}; var head = 0; var tail = 0; var best = 0; var max = s.length; while (tail < max) { var letter = s.charAt(tail); var jump = positions[letter]; tail++; if (jump && jump > head) { head = jump; } else { var diff = tail  head; if (diff > best) { best = diff; }; }; positions[letter] = tail; }; return best; };

@ryan90 26 is misleading? How so? The solution posted here beats 100%, before I added "26" and "offset" it beat 93%.