[Java/C++/Python] Prefix + BitMask
Intuition\nSimilar to 1371. Find the Longest Substring Containing Vowels in Even Counts.\n\n\n## Explanation\nWe have 10 + 1 types of palindromes.\nUse any numb
## **Intuition**\nSimilar to [1371. Find the Longest Substring Containing Vowels in Even Counts](https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts/discuss/531840/JavaC++Python-One-Pass).\n<br>\n\n## **Explanation**\nWe have 10 + 1 types of palindromes.\nUse any number as the middle character, or don\'t have a middle character.\n<br>\n\n## **Complexity**\nTime `O(10N)`\nSpace `O(1024)`\n<br>\n\n**Java:**\n```java\n    public int longestAwesome(String s) {\n        int res = 0, cur = 0, n = s.length(), seen[] = new int[1024];\n        Arrays.fill(seen, n);\n        seen[0] = -1;\n        for (int i = 0; i < n; ++i) {\n            cur ^= 1 << (s.charAt(i) - \'0\');\n            for (int a = 0; a < 10; ++a)\n                res = Math.max(res, i - seen[cur ^ (1 << a)]);\n            res = Math.max(res, i - seen[cur]);\n            seen[cur] = Math.min(seen[cur], i);\n        }\n        return res;\n    }\n```\n\n**C++:**\n```cpp\n    int longestAwesome(string s) {\n        int res = 0, cur = 0, n = s.size();\n        vector<int> seen(1024, n);\n        seen[0] = -1;\n        for (int i = 0; i < n; ++i) {\n            cur ^= 1 << (s[i] - \'0\');\n            for (int a = 0; a < 10; ++a)\n                res = max(res, i - seen[cur ^ (1 << a)]);\n            res = max(res, i - seen[cur]);\n            seen[cur] = min(seen[cur], i);\n        }\n        return res;\n    }\n```\n\n**Python:**\n```py\n    def longestAwesome(self, s):\n        res, cur, n = 0, 0, len(s)\n        seen = [-1] + [n] * 1024\n        for i, c in enumerate(s):\n            cur ^= 1 << int(c)\n            for a in xrange(10):\n                res = max(res, i - seen[cur ^ (1 << a)])\n            res = max(res, i - seen[cur])\n            seen[cur] = min(seen[cur], i)\n        return res\n```\n
[]