-
Notifications
You must be signed in to change notification settings - Fork 3
/
1371.cpp
38 lines (38 loc) · 865 Bytes
/
1371.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Solution {
public:
int toBitmask(char& c) {
if (c == 'a') {
return 1;
}
if (c == 'e') {
return 1 << 1;
}
if (c == 'i') {
return 1 << 2;
}
if (c == 'o') {
return 1 << 3;
}
if (c == 'u') {
return 1 << 4;
}
return 0;
}
int findTheLongestSubstring(string s) {
int currentMask = 0;
int length = 0;
unordered_map<int, int> mp;
mp[0] = -1;
int n = s.size();
for (int i = 0; i < n; ++i) {
currentMask ^= toBitmask(s[i]);
if (mp.count(currentMask)) {
length = max(length, i - mp[currentMask]);
}
else {
mp[currentMask] = i;
}
}
return length;
}
};