# [Leetcode]3. Longest Substring Without Repeating Characters

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

［Dynamic Programming] [Hashtable]

int placeholder[256]; //用来存储当前最长连续非重复字符串，1表示在其中，0表示不在其中
int tailHolder[256]; //用来存储当前尾部最长连续非重复字符串, 也是0、1标示
int tailIndex[256]; //用来存储当前尾部最长连续非重复字符串中各个char在串中的index，从1开始
int maxLetter[length]; //length为输入string的长度，它用来存储长度从1~length的substring中最长连续非重复字符串的长度
int isTailed; //表明当前最长连续非重复字符串是否是尾部的substring
int tail_max;

Linear scan the string s
And parse every character s[i]

[1].check the isTailed
[1.1]True! check (tailHolder[s[i]]==1)?
[1.1.1]True!
updateTailHolder();
updatePlaceHolder();
tail_max = tail_max - tailIndex[s[i]] + 1;
updateIndex(tail_max_string);
isTailed = 0;
[1.1.2]False!
tail_max++;
tailIndex[s[i]] = tail_max;
placeHolder[s[i]] = 1;
tailHolder[s[i]] = 1;
[1.2].False! check (tailHolder[s[i]]==1)?
[1.2.1]True!
updateTailHolder();
updatePlaceHolder();
tail_max = tail_max - tailIndex[s[i]] + 1;
updateIndex(tail_max_string);
[1.2.2]False! Check (tail_max+1==maxLetter[i-1])?
[1.2.2.1]True
tailHolder[s[i]] = 1;
assign(placeHolder, tailHolder);
tail_max++;
tailIndex[s[i]] = tail_max;
[1.2.2.2]False
tailHolder[s[i]] = 1;
tail_max++;
tailIndex[s[i]] = tail_max;
END