Find the Longest Substring Containing Vowels in Even Counts LeetCode solution in C++
1// When the xor of all the even times numbers are done it results in 0. The xor2// of the vowels are done by indicating them with a single digit and the xor3// value is stored in a map4class Solution {5public:6int findTheLongestSubstring(string s) {7int x = 0;8unordered_map<int, int> mp;9mp[0] = -1;10int n = 0;11for (int i = 0; i < s.length(); i++) {12if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') {13x ^= (s[i] - 'a' + 1);14if (mp.find(x) == mp.end()) mp[x] = i;15}16if (mp.find(x) != mp.end()) n = max(n, i - mp[x]);17}18return n;19}20};