-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create 1371. Find the Longest Substring Containing Vowels in Even Counts
- Loading branch information
1 parent
4ae12b2
commit 04a4e76
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
1371. Find the Longest Substring Containing Vowels in Even Counts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |