class Solution {
public:
int lengthOfLongestSubstring(string s) {
vector<int> loc(256, -1);
int start = -1, res(0);
for(int i = 0; i < s.size(); ++i){
if(loc[s[i]] > start) start = loc[s[i]];
if(i - start > res) res = i - start;
loc[s[i]] = i;
}
return res;
}
};
LeetCode之Longest Substring Without Repeating Characters
最新推荐文章于 2021-12-03 15:58:56 发布