Given a string s, find the length of the longest substring without repeating characters.
new solution update 2022.02.14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
classSolution { public: intlengthOfLongestSubstring(string s){ int arr[128]{false}; int res = 0; for(int l=0, r = 0; r < s.length(); r++) { while(arr[s[r]]) { arr[s[l++]]--; } arr[s[r]]++; res = max(res, r - l + 1); } return res; } };