无重复字符的最长子串
给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int slowPoint = 1;
int fastPoint = 0;
int result = 0;
unordered_map<char, int> signMap{};
for(;fastPoint < s.size(); fastPoint++)
{
if(signMap[s[fastPoint]] != 0) //重复
{
while(slowPoint <= signMap[s[fastPoint]])
{
signMap[s[slowPoint - 1]] = 0;
slowPoint++;
}
}
//因为记录的下标偏移了1 所以slowPoint要-1
result = result > (fastPoint - (slowPoint - 1) + 1) ? result : (fastPoint - (slowPoint - 1) + 1);
signMap[s[fastPoint]] = fastPoint + 1;
}
return result;
}
};