标签:ash size -- == order off string 字符串 sub
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_map<char, int> hash;
int res = 0;
for(int i = 0, j = 0; j < s.size(); j++)
{
if(++hash[s[j]] > 1)
{
while(i < j)
{
hash[s[i]]--;
i++;
if(hash[s[j]] == 1) break;
}
}
res = max(res, j- i + 1);
}
return res;
}
};
【剑指offer】【字符串】48. 最长不含重复字符的子字符串
标签:ash size -- == order off string 字符串 sub
原文地址:https://www.cnblogs.com/Trevo/p/12823063.html