1542. Find Longest Awesome Substring.cpp
Code\n\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n        int f[1 << 10]; \n        int digits[10]; \n        memset(f, -1, sizeof(f));\n  
**Code**\n```\nclass Solution {\npublic:\n    int longestAwesome(string s) {\n        int f[1 << 10]; \n        int digits[10]; \n        memset(f, -1, sizeof(f));\n        memset(digits, 0, sizeof(digits));\n        f[0] = 0;\n        int res = 0;\n        for (int i = 1; i <= s.length(); i++) {\n            digits[s[i-1]-\'0\'] = (digits[s[i-1]-\'0\'] + 1) % 2;\n            int value = 0;\n            for (int j = 0; j < 10; j++)\n                if (digits[j] == 1) value += 1 << j;\n            if (f[value] > -1) res = max(res, i-f[value]);\n            for (int j = 0; j < 10; j++) {\n                if (digits[j] == 0) {\n                    int newValue = value + (1 << j);\n                    if (f[newValue] > -1) res = max(res, i-f[newValue]);\n                } else {\n                    int newValue = value - (1 << j);\n                    if (f[newValue] > -1) res = max(res, i-f[newValue]);\n                }\n            }\n            if (f[value] == -1) f[value] = i; \n        }\n        return res;\n    }\n};\n```
['C']