-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15sep.txt
29 lines (27 loc) · 894 Bytes
/
15sep.txt
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
class Solution {
public:
static int findTheLongestSubstring(string& s) {
char vow[26];
memset(vow, -1, 26);
vow[0]=0, vow['e'-'a']=1, vow['i'-'a']=2, vow['o'-'a']=3, vow['u'-'a']=4;
const int n=s.size();
vector<char> bmask(n+1, 0);// 1-indexed prefix sum
int first_seen[32]; // index for different bmask first seen
memset(first_seen, -1, sizeof(first_seen));
int len=0;
first_seen[0]=0; // no vowels for bmask[0]
for(int i=0; i<n; i++){
const char x=vow[s[i]-'a'];
const char curr=bmask[i+1]=bmask[i]^(x==-1?0:(1<<x));
if (first_seen[curr]==-1) first_seen[curr]=i+1;
len=max(len, i+1-first_seen[curr]);
}
return len;
}
};
auto init = []() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 'c';
}();