leetcode的Longest Substring Without Repeating Characters解法好麻烦啊# JobHunting - 待字闺中
p*3
1 楼
http://leetcode.com/2011/05/longest-substring-without-repeating
丢个简单的:
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_map mp;
int ret = 0;
int beg = 0;
for (int i = 0; i < s.length(); i++)
{
if (mp.find(s.at(i)) != mp.end() && mp[s.at(i)] >= beg)
beg = mp[s.at(i)] + 1;
mp[s.at(i)] = i;
ret = max(ret, i - beg + 1);
}
return ret;
}
};
文康,要不给改改?
丢个简单的:
class Solution {
public:
int lengthOfLongestSubstring(string s) {
unordered_map
int ret = 0;
int beg = 0;
for (int i = 0; i < s.length(); i++)
{
if (mp.find(s.at(i)) != mp.end() && mp[s.at(i)] >= beg)
beg = mp[s.at(i)] + 1;
mp[s.at(i)] = i;
ret = max(ret, i - beg + 1);
}
return ret;
}
};
文康,要不给改改?