3.无重复字符的最长子串

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_set<char> uod_set;
        int n = s.size();
        int count = 0;
        int length = 0;
        int l_point, r_point = 0;
        for(l_point = 0; l_point < n; l_point++){
            while(!uod_set.count(s[r_point]) && r_point < n){
                uod_set.insert(s[r_point]);
                r_point++;
            }
            length = r_point - l_point;
            if(length > count)
                count = length;
            uod_set.erase(s[l_point]);
        }
        return count;
    }
};

你可能感兴趣的:(力扣每日刷题,leetcode,算法,职场和发展)