C++


  • 0
    T
    class Solution {
    public:
        int lengthOfLongestSubstring(string s) {
            vector<bool> alpha(256, false);
            int maxl = 0;
            int l = 0, r = 0;
            while (r < s.length()) {
                while (r < s.length() && !alpha[s[r]]) {
                    alpha[s[r++]] = true;
                    maxl = max(maxl, r - l);
                }
                while (l < r) {
                    alpha[s[l]] = false;
                    if (s[l++] == s[r]) break;
                }
            }
            return maxl;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.