由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 那位大侠帮看看 Longest Substring Without Repeating Characters 这个为啥总是不对
相关主题
Leetcode- Longest Substring Without Repeating Characters 的 test case问问题
leetcode的Longest Substring Without Repeating Characters解法好麻烦啊新鲜出炉的Yelp面经[已更新]
(已解决,code错了) online judge 有的时候会有点小bug吗?longest repeated substring怎么做?(亚麻刚刚被问到的题)
请教:这个10来行的leetcode程序有什么问题?请教suffix tree and longest repeated substring
amazon onsite 请教Longest Valid Parentheses
LC Longest substr w/o rep char这道题咋做?
骑驴找马小结问一个经典题目
an interview question请教一道题目
相关话题的讨论汇总
话题: int话题: len话题: max话题: mp话题: jj
进入JobHunting版参与讨论
1 (共1页)
i******t
发帖数: 22541
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;
}
};
1 (共1页)
进入JobHunting版参与讨论
相关主题
请教一道题目amazon onsite 请教
G phone interviewLC Longest substr w/o rep char
一道Google面试题,怎么做?(题目描述有误,已修改)骑驴找马小结
finds all repeated substrings in the string --- YAHOO interview questionan interview question
Leetcode- Longest Substring Without Repeating Characters 的 test case问问题
leetcode的Longest Substring Without Repeating Characters解法好麻烦啊新鲜出炉的Yelp面经[已更新]
(已解决,code错了) online judge 有的时候会有点小bug吗?longest repeated substring怎么做?(亚麻刚刚被问到的题)
请教:这个10来行的leetcode程序有什么问题?请教suffix tree and longest repeated substring
相关话题的讨论汇总
话题: int话题: len话题: max话题: mp话题: jj