Longest Substring Without Repeating Characters

Posted xpp

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Longest Substring Without Repeating Characters相关的知识,希望对你有一定的参考价值。

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int hashTable[255];
        fill(hashTable, hashTable+255, -1);
        
        int start = 0, maxLen = 0;
        for(int i=0; i<s.size(); ++i)
        {
            if(hashTable[s[i]] >= start)
            {
                maxLen = max(maxLen, i-start);
                start = hashTable[s[i]]+1;
            }
            
            hashTable[s[i]] = i;
        }
        
        return max(maxLen, (int)s.size()-start);
    }
};

 

以上是关于Longest Substring Without Repeating Characters的主要内容,如果未能解决你的问题,请参考以下文章

3. Longest Substring Without Repeating Characters

Leetcode-Longest Substring Without Repeating Characters

[LeetCode] Longest Substring Without Repeating Characters

Longest Substring Without Repeating Characters

Leetcode 3. Longest Substring Without Repeating Characters

leetcode: Longest Substring Without Repeating Characters