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.
#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
int lengthOfLongestSubstring(string s) {
if(s.empty())
return 0;
if(s.size()==1)
return 1;
int i=0;
int ret=0;
int start=0;
for(int j=start+1;j!=s.size();j++)
{
for(i=start;i!=j;i++)
{
if(s[j]==s[i])
{
start=i+1;
break;
}
}
if(j-start+1>ret)
ret=j-start+1;
}
return ret;
}
};