leetcode 3. Longest Substring Without Repeating Characters

来源:互联网 发布:编程方法学 编辑:程序博客网 时间:2024/06/10 10:43
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;}};

0 0