标签:leetcode
链接:https://leetcode.com/problems/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.
Hide Tags Hash Table Two Pointers String
求给出字符串中的不重复的最大子串长度。
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int result=0,n;
string temp="";
for(int i=0;i<s.length();i++)
{
n=temp.find(s[i]);
if(n<0)
temp+=s[i];
else
{
if(result<temp.size())
result=temp.size();
temp=temp.substr(n+1)+s[i];
}
}
if(result<temp.size())
result=temp.size();
return result;
}
};
版权声明:本文为博主原创文章,未经博主允许不得转载。
3 Longest Substring Without Repeating Characters
标签:leetcode
原文地址:http://blog.csdn.net/efergrehbtrj/article/details/46822335