Skip to content

Commit 1b4fea4

Browse files
authored
Create 1371. Find the Longest Substring Containing Vowels in Even Counts (#586)
2 parents 4ae12b2 + 04a4e76 commit 1b4fea4

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
class Solution {
3+
public:
4+
map<char,int> s = {{'a',0},{'e',1},{'i',2},{'o',3},{'u',4}};
5+
6+
int findTheLongestSubstring(string str) {
7+
int mask=0;
8+
vector<int> pre;
9+
for(auto e : str){
10+
if(s.find(e) != s.end()){
11+
mask = mask ^ (1<<(e-'a'));
12+
}
13+
pre.push_back(mask);
14+
}
15+
16+
// for(auto e : pre) cout << e << " ";
17+
18+
map<int,int> m; m[0] = -1;
19+
int ans=0;
20+
for(int i=0; i<pre.size(); i++){
21+
auto e = pre[i];
22+
if(m.find(e) == m.end()){
23+
m[e] = i;
24+
}
25+
26+
ans = max(ans, i-m[e]);
27+
}
28+
29+
return ans;
30+
}
31+
};
32+
33+
34+
// xor
35+
// bit unchagned
36+
// 0 0 0
37+
// 1 0 1
38+
// bit flip
39+
// 0 1 1
40+
// 1 1 0

0 commit comments

Comments
 (0)