/** * @param {string} s * @return {number} */ var lengthOfLongestSubstring = function (s) { if (!s) { return0; } let result = 0; let tmp = ""; for (let i = 0; i < s.length; i++) { const index = tmp.indexOf(s[i]); if (index === -1) { tmp += s[i]; if (tmp.length > result) { result = tmp.length; } } else { tmp = tmp.substring(index + 1) + s[i]; } } return result; };