###### 仰望星空，脚踏实地。

Stay Foolish ！Stay hungry ！

###### 【LeetCode】3 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.

Solution1

public class Solution {
public int lengthOfLongestSubstring(String s) {
boolean []exist = new boolean[256];
int i=0,maxLen = 0;
for(int j=0;j<s.length();j++)
{
while(exist[s.charAt(j)])
{
exist[s.charAt(i)] = false;
i++;
}
exist[s.charAt(j)]=true;
maxLen = Math.max(j-i+1, maxLen);
System.out.println();
}
return maxLen;
}
}

Solution2 HashMap

public class Solution {
public int lengthOfLongestSubstring(String s) {
int maxLen = 0;
int availableFrom = 0;
Map<Character,Integer> map = new HashMap<Character,Integer>();
for(int j=0;j<s.length();j++)
{
if(map.containsKey(s.charAt(j)))
{
int last = map.get(s.charAt(j));
availableFrom = Math.max(availableFrom, last+1);
}
maxLen = Math.max(maxLen, j-availableFrom+1);
map.put(s.charAt(j), j);
}
return maxLen;
}
}

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

2016-06-20 20:36:28

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

2013-11-23 04:25:39

#### LeetCode 3.Longest Substring Without Repeating Characters c语言版

2017-07-15 17:35:47

#### leetcode 3 Longest Substring Without Repeating Characters最长无重复子串

2016-04-05 22:27:27

#### [LeetCode] 003. Longest Substring Without Repeating Characters (Medium) (C++/Java/Python)

2015-02-27 12:55:12

#### leetcode 3 : Longest Substring Without Repeating Characters 最长无重复子串 (C# 语言版）

2016-04-05 09:47:32

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

2014-02-26 01:53:37

#### 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

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

2016-09-03 12:16:17

## 不良信息举报

【LeetCode】3 Longest Substring Without Repeating Characters