You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* * @lc app=leetcode.cn id=3 lang=javascript * * [3] 无重复字符的最长子串 */// @lc code=start/** * @param {string} s * @return {number}a b c a b c b b i ja b c a b c b b i j{ a: 1, b: 1, c: 1}(72 ms) */functionlengthOfLongestSubstring(s){letans=0;constmap=newMap();leti=0;for(letj=0;j<s.length;j++){constv=s[j];map.set(v,(map.get(v)||0)+1);// 如果当前v代表字符,它是由重复的while(map.get(v)>1){map.set(s[i],map.get(s[i])-1);i++;}ans=Math.max(j-i+1,ans)}returnans;}// @lc code=end
3. 无重复字符的最长子串
Description
Difficulty: 中等
Related Topics: 哈希表, 字符串, 滑动窗口
给定一个字符串
s
,请你找出其中不含有重复字符的 **最长子串 **的长度。示例 1:
示例 2:
示例 3:
提示:
s
由英文字母、数字、符号和空格组成The text was updated successfully, but these errors were encountered: