mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
25 lines
624 B
C++
25 lines
624 B
C++
class Solution {
|
|
public:
|
|
int lengthOfLongestSubstring(string s) {
|
|
map<char, short> v;
|
|
int max_num = 0;
|
|
for (int i = 0; i < s.size(); ++i) {
|
|
if (v.find(s[i]) != v.end()) {
|
|
if (max_num < v.size()) {
|
|
max_num = v.size();
|
|
}
|
|
i = v.find(s[i])->second + 1;
|
|
v.clear();
|
|
}
|
|
if (i >= s.size()) {
|
|
break;
|
|
}
|
|
v[s[i]] = i;
|
|
if (max_num < v.size()) {
|
|
max_num = v.size();
|
|
}
|
|
}
|
|
return max_num;
|
|
}
|
|
};
|