题目
给定一个字符串,求最长的不重复的子串。
Longest Substring Without Repeating Characters
Given a string, find the length of the **longest substring** without repeating characters.
解题代码
class Solution {
public:
int hashmap[130];
int lengthOfLongestSubstring(string s) {
int max=0;
int n=s.size();
for(int i=0,j=0;j<n;j++)
{
hashmap[s[j]]++;
while(hashmap[s[j]]>1){
hashmap[s[i++]]--;
}
if(j-i+1 > max){
max = j-i+1;
}
}
return max;
}
};
网友评论