【LeetCode】- Longest Substring Without Repeating Characters

Easy!

Best Sufficient: O(n)

class Solution {

public:
    int lengthOfLongestSubstring(string s) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        
        bool hash[26];
        for(int i=0; i<26; i++)
        {
            hash[i] = false;
        }
        
        int len = s.size();
        int count = 0;
        for(int l=0; l<len; l++)
        {
            int index = s[l] - 'a';
            if(false == hash[index])
            {
                hash[index] = true;
                count++;
            }
        }
        
        return count;
    }
};

Why can't pass ?

Error Cases is Right in my VS2010...

原文地址:https://www.cnblogs.com/CathyGao/p/3139937.html