題目c++
c++code
class Solution { public: map<char,int> m; int a[100005]; int lengthOfLongestSubstring(string s) { int len = s.length(); if(len==0) return 0; a[0]=1; m[s[0]]=1; int mm=1; for(int i=1;i<len;i++) { if(m[s[i]]==0) { a[i]=a[i-1]+1; mm = max(mm,a[i]); m[s[i]]=i+1; } else { if(m[s[i]]-1>=i-a[i-1]) { a[i]=i-m[s[i]]+1; } else a[i]=a[i-1]+1; mm = max(mm,a[i]); m[s[i]]=i+1; } } return mm; } };