注意边界
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <memory.h>
using namespace std;
class Solution {
public:
int lengthOfLongestSubstring(string s)
{
int len = s.size();
int a[len+1];
for(int i=0;i<len;i++)
a[i] = 1;
int Max = 0;
for(int i=0;i<len;i++)
{
int flag = 1;
set<int> record;
record.insert(s[i]);
int j;
for(j=i;j<s.size()-1;j++)
{
if(record.find(s[j+1])==record.end())
{
record.insert(s[j+1]);
}
else
{
a[i] = j-i+1;
break;
}
}
if(j==s.size()-1)
a[i] = s.size()-i;
}
for(int i=0;i<len;i++)
Max = max(a[i],Max);
return Max;
}
};