类似于紫书例题8-7.
用滑动窗口。
class Solution { public: int lengthOfLongestSubstring(string s) { set<char>ss; int left=0,right=0,ans=0; while(right<s.length()) { while(right<s.length()&&!ss.count(s[right])) ss.insert(s[right++]); ans=max(ans,right-left); ss.erase(s[left++]); } return ans; } };