0%

# leetcode no.3

Posted on 2015-04-15 Edited on 2020-01-12 In leetcode Views: Disqus:

*Longest Substring Without Repeating Characters *

### description

Given a string, find the length of the longest substring without repeating characters.
For example, the longest substring without repeating letters for “abcabcbb” is “abc”,
which the length is 3. For “bbbbb” the longest substring is “b”, with the length of 1.

### 分析

源码这次是参考了这个代码，
tail 表示的当前子串的起始点位置，tail从-1开始就包括的串的长度是1的边界。其实我
也是猜的（逃

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    int ct[256];
        memset(ct, -1, sizeof(ct));
    	int tail = -1;
    	int max = 0;
    	for (int i = 0; i < s.size(); i++){
    		if (ct[s[i]] > tail)
    			tail = ct[s[i]];
    		if (i - tail > max)
    			max = i - tail;
    		ct[s[i]] = i;
    	}
    	return max;

Related Posts

- Reverse Integer
- 34_Search_for_a_Range
- summary-ranges-228
- Number of 1 Bits
- Path Sum

请我喝杯咖啡

WeChat Pay

Alipay

- Post author: Nicksxs
- Post link: https://nicksxs.me/2015/04/15/Leetcode-No-3/
- Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.