Skip to content

Commit

Permalink
Create 1371. Find the Longest Substring Containing Vowels in Even Counts
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Sep 15, 2024
1 parent 4ae12b2 commit 04a4e76
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 1371. Find the Longest Substring Containing Vowels in Even Counts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

class Solution {
public:
map<char,int> s = {{'a',0},{'e',1},{'i',2},{'o',3},{'u',4}};

int findTheLongestSubstring(string str) {
int mask=0;
vector<int> pre;
for(auto e : str){
if(s.find(e) != s.end()){
mask = mask ^ (1<<(e-'a'));
}
pre.push_back(mask);
}

// for(auto e : pre) cout << e << " ";

map<int,int> m; m[0] = -1;
int ans=0;
for(int i=0; i<pre.size(); i++){
auto e = pre[i];
if(m.find(e) == m.end()){
m[e] = i;
}

ans = max(ans, i-m[e]);
}

return ans;
}
};


// xor
// bit unchagned
// 0 0 0
// 1 0 1
// bit flip
// 0 1 1
// 1 1 0

0 comments on commit 04a4e76

Please sign in to comment.