/** * @param {string} s * @return {number} */ var lengthOfLongestSubstring = function (s) { let max = 0; let num = 0; let hasp; const hashMap = new Map() for (let i = 0; i < s.length; i++) { hasp = s.charAt(i); if (hashMap.get(hasp) || hashMap.get(hasp) === 0) { num = Math.max(num, hashMap.get(hasp) + 1); } max = Math.max(max, i - num + 1); hashMap.set(hasp, i) } return max; }
标签:子串,字符,hashMap,get,max,num,let,hasp,最长 From: https://www.cnblogs.com/yadayou/p/17846763.html