LeetCode || Longest Substring Without Repeating Characters

原创 2015年07月10日 16:26:34
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        if(s.size() == 0)
            return 0;
        if(s.size() == 1)
            return 1;

        int hashTable[256];
        for(int i = 0; i < 256; i++)
            hashTable[i] = -1;

        int start = 0;
        int end = 1;
        int result = 1;
        hashTable[s[start]] = 0;
        for(; end <= s.size(); end++) {
            if(end == s.size()) {
                int tmp = end - start;
                if(tmp > result)
                    result = tmp;
                continue;
            }
            if(hashTable[s[end]] < start) {
                hashTable[s[end]] = end;
                continue;
            } else {
                int tmp = end - start;
                if(tmp > result)
                    result = tmp;
                start = hashTable[s[end]] + 1;
                hashTable[s[end]] = end;
            }

        }
        return result;
    }
};

LeetCode Algorithms 3. Longest Substring Without Repeating Characters 题解

题目: Given a string, find the length of the longest substring without repeating characters.

《LeetBook》leetcode题解(3):Longest Substring Without Repeating Characters[M]——哈希判断重复

003. Longest Substring Without Repeating Characters[M]题目:Given a string, find the length of the long...

LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度

Given a string, find the length of the longest substring without repeating characters. Examples: Giv...

[Leetcode #3]Longest Substring Without Repeating Characters 无重复字符的最长子串

原题地址:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 题目要求是:给定一个字符串,找出...

leetcode之Longest Substring Without Repeating Characters

如题,这里的字符串不止是

LeetCode之3_Longest Substring Without Repeating Characters

题目原文:   Given a string, find the length of the longest substring without repeating characters. For...

Leetcode || Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, ...

【LeetCode OJ 003】Longest Substring Without Repeating Characters

题目链接:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 题目:Given a str...

[LeetCode]003-Longest Substring Without Repeating Characters

题目: Given a string, find the length of the longest substring without repeating characters. For exam...

Leetcode 3. Longest Substring Without Repeating Characters The Solution of Python and Javascript

Given a string, find the length of the longest substring without repeating characters.Examples:Given...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LeetCode || Longest Substring Without Repeating Characters
举报原因:
原因补充:

(最多只允许输入30个字)