mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 3_beihe.cpp
This commit is contained in:
parent
ada93fa0db
commit
cefeb5d972
24
LeetCode-CN/3_beihe.cpp
Normal file
24
LeetCode-CN/3_beihe.cpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user