那位大侠帮看看 Longest Substring Without Repeating Characters 这个为啥总是不对# JobHunting - 待字闺中
i*t
1 楼
感觉挺简单的啊 和 oj答案不一样 哪位帮看看啊
class Solution {
public:
int lengthOfLongestSubstring(string s) {
map mp;
int max_len =0;
int n=s.size();
int j =0;
for(int i=0;i {
char c = s.at(i);
if( mp.find(c)!=mp.end() ) // found
{
int len = i-j;
if(len>max_len)
{
max_len = len;
}
int jj = mp[c];
for(int k=j;k<=jj;k++) // erase from j to current position
{
mp.erase( s.at(k) );
}
j=jj+1; // set new start position
}
mp[c] = i;
}
return max_len;
}
};
class Solution {
public:
int lengthOfLongestSubstring(string s) {
map
int max_len =0;
int n=s.size();
int j =0;
for(int i=0;i
char c = s.at(i);
if( mp.find(c)!=mp.end() ) // found
{
int len = i-j;
if(len>max_len)
{
max_len = len;
}
int jj = mp[c];
for(int k=j;k<=jj;k++) // erase from j to current position
{
mp.erase( s.at(k) );
}
j=jj+1; // set new start position
}
mp[c] = i;
}
return max_len;
}
};