【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...

posted on 2013-06-17 11:38  highstar88  阅读(129)  评论(0编辑  收藏  举报

导航