2019-02-13 algorithm leetcode -lengthOfLongestSubstring Leetcode题解之 —— 无重复字符的最长子串 思路 暴力解法 空字判断 连续字串 及时更新新的子串数组 更新max 题解 123456789101112131415161718192021222324252627282930/** * @param {string} s * @return {number} */var lengthOfLongestSubstring = function (s) { const len = s.length; let [max, count, cache] = [1, 0, []]; if (!s) { return 0; } while (count < len) { const current = s[count]; if(cache.includes(current)) { const finalIndex = cache.lastIndexOf(current); const filteredCache = cache.slice(finalIndex + 1); cache = [...filteredCache, current]; }else { cache.push(current); } max = Math.max(cache.length, max); count++; } return max;}; 作者 : zhaoyang Duan 地址 : https://ddzy.github.io/blog/2019/02/13/leetcode-lengthOfLongestSubstring/ 来源 : https://ddzy.github.io/blog 著作权归作者所有,转载请联系作者获得授权。