题目描述链接:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
解题思路:双指针
LeetCode C++参考代码如下:
class Solution { public: unordered_set<char>record; int lengthOfLongestSubstring(string s) { int rk=-1; int res=0; for(int i=0;i<s.size();i++){ if(i!=0){ record.erase(s[i-1]); } while(rk+1<s.size()&&!record.count(s[rk+1])){ rk++; record.insert(s[rk]); } res=max(rk-i+1,res); } return res; } };