您的位置:首页 > 编程语言 > C语言/C++

leetcode 3. Longest Substring Without Repeating Characters

2017-01-28 20:21 555 查看
class Solution {
public:
int lengthOfLongestSubstring(string s)
{
string now;
decltype(now.size()) max = 0;
for (auto a : s)
{
if (now.find(a) == string::npos)
{
now += a;
}
else
{
if (now.size() > max)
{
max = now.size();
}
auto index = now.find(a);
now.erase(0, index + 1);
now += a;
}
}
if (now.size() > max)
{
max = now.size();
}
return max;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息