12ms,beat 96.1%


  • 0
    Y

    '''
    class Solution {
    public:
    int lengthOfLongestSubstring(string s) {
    int len = s.length();
    int m[256];
    memset(m, -1, sizeof(m));
    int i = 0, start = 0;;
    int maxL = 0;
    while(i < len){
    if(m[s[i]] == -1){
    m[s[i]] = i;
    }
    else{
    maxL = max(maxL, i - start);
    int tmp = start;
    start = m[s[i]] + 1;
    for(int k = tmp; k < start; ++k)
    m[s[k]] = -1;
    m[s[i]] = i;
    }
    ++i;
    }
    maxL = max(maxL, i - start);
    return maxL;
    }
    };
    ''''


Log in to reply
 

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