class Solution {
public:
int lengthOfLongestSubstring(string s) {
// AcWing基础课 双指针模板题
unordered_map<char, int> hash;
int res = 0;
for(int i = 0, j = 0 ; i < s.size() ; i ++)
{
hash[s[i]] ++ ;
while(hash[s[i]] > 1)
{
hash[s[j]] --;
j ++;
}
res = max(res, i - j + 1);
}
return res;
}
};
LeetCode 3. 无重复字符的最长子串
最新推荐文章于 2024-01-11 19:22:57 发布