Find Longest Awesome Substring LeetCode solution in C++
1class Solution {2public:3int longestAwesome(string s) {4unordered_map<int, int> map;5int mask = 0, maxL = 0;6map[mask] = -1;78for (int i = 0; i < s.size(); ++i) {9int ch = s[i] - '0';10mask ^= (1 << ch);1112if (map.find(mask) != map.end()) {13maxL = max(maxL, i - map[mask]);14}1516for (int x = 0; x <= 9; ++x) {17int newMask = mask ^ (1 << x);18if (map.find(newMask) != map.end()) {19maxL = max(maxL, i - map[newMask]);20}21}2223if (map.find(mask) == map.end()) {24map[mask] = i;25}26}27return maxL;28}29};