3. Longest Substring Without Repeating Characters

#### QUESITON:

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

Examples:

Given `"abcabcbb"`, the answer is `"abc"`, which the length is 3.

Given `"bbbbb"`, the answer is `"b"`, with the length of 1.

Given `"pwwkew"`, the answer is `"wke"`, with the length of 3. Note that the answer must be a substring, `"pwke"` is a subsequenceand not a substring.

#### SOLUTION:

``````class Solution {
public int lengthOfLongestSubstring(String s) {
if(s.length()<=1) return s.length();
char[] chars = s.toCharArray();
List<Character> list = new ArrayList<>();
int result = 0;
for(int i = 0;i<chars.length;i++){
int index = list.indexOf(chars[i]);
if(index==-1){
result = Math.max(result,list.size());
}else {
ArrayList<Character> tmplist =new ArrayList<>();
for(int j = list.size()-1;j>index;j--){
}
list = tmplist;
result = Math.max(result,list.size());
}

}
return result;
}
}
``````
``````class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
tmp = ""
result = 0
for i in range(0,len(s),):
index = tmp.find(s[i])
tmp = tmp+s[i]
if index != -1 :
tmp = tmp[index+1:]
result = max(result,len(tmp))
return result
``````
>