# Longest Substring Without Repeating Characters

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.

class Solution {
public:
int lengthOfLongestSubstring(string s) {
const int SIZE=256;
int record[SIZE];
memset(record,-1,sizeof(record));// 当顺序遍历到字符 s[i]，s[i] 最后出现的位置

int final_ans=0;
int new_start=0; // 这一轮不重复字符串的起点
for(int i=0;i<s.size();++i){
if(record[(int)s[i]]>=new_start)
new_start=record[(int) s[i]]+1;//新的起点
if(i-new_start+1>final_ans) // 更新 final_ans
final_ans=i-new_start+1;
record[(int)s[i]]=i; // 更新 s[i] 最后一次出现的地方
}
return final_ans;
}
};

#### LeetCode(3) Longest Substring Without Repeating Characters

2013-11-23 04:25:39

#### Longest Substring Without Repeating Characters -- LeetCode

2014-02-26 01:53:37

#### leetcode:3. Longest Substring Without Repeating Characters (java)

2016-06-20 20:36:28

#### LeetCode 第三题，Longest Substring Without Repeating Characters

2014-08-03 20:38:44

#### 字符串+哈希表+小动态规划（Longest Substring Without Repeating Characters -- LeetCode）

2016-09-03 12:16:17

#### [Leetcode][python]Longest Substring Without Repeating Characters

2017-08-08 00:58:30

#### Longest Substring Without Repeating Characters —— java

2018-02-11 11:25:32

#### LeetCode 149 Longest Substring Without Repeating Characters

2014-11-02 09:50:54

#### LeetCode 3. Longest Substring Without Repeating Characters（C++）

2017-03-22 13:56:21

#### leetcode python - Longest Substring Without Repeating Characters

2017-04-01 15:07:19