[LeetCode]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) {
vector<int>hash (300,-1);
int i,j;
i=0;
j=0;
if(s.size()==0)
return 0;
if(s.size()==1)
return 1;
int ret=0;
while(i<=j && j<s.length()){
if(hash[s[j]]!=-1){
for(;i<hash[s[j]];++i){
hash[s[i]] = -1;
}
i = hash[s[j]]+1;
hash[s[j]]=j;
}
else{
hash[s[j]]=j;
}
ret = max(ret,j-i+1);
++j;
}
return ret;
}

};

• 本文已收录于以下专栏：

[LeetCode - 滑动窗口] 3. Longest Substring Without Repeating Characters

1 问题 Given a string, find the length of the longest substring without repeating characters. Exa...

leetcode: Longest Substring Without Repeating Characters

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

leetcode4 ---Longest Substring Without Repeating Characters

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

LeetCode | 3. Longest Substring Without Repeating Characters

leetcode.com 3. Longest Substring Without Repeating Characters

(leetcode) Longest Substring Without Repeating Characters

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

LeetCode- 3. Longest Substring Without Repeating Characters

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

leetcode_3 - Longest Substring Without Repeating Characters

leetcode_3 : Longest Substring Without Repeating Characters标签（空格分隔）： leetcode string twoPoints setGi...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)