跳转至

无重复字符的最长子串⚓︎

Leetcode题目链接

描述⚓︎

详见中文题目链接

解答⚓︎

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int n = s.length();
        vector<int> last(256, -1);
        int res = 0;
        for (int left = 0, right = 0; right < n; right++) {
            left = max(left, last[s[right]] + 1);
            res = max(res, right - left + 1);
            last[s[right]] = right;
        }
        return res;
    }
};