Simple Java PreSum + BitMask Solution
Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(2^9)\n\n# Code\n\nclass Solution {\n    public int longestAwesome(String s) {\n        int n = s.
# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(2^9)\n\n# Code\n```\nclass Solution {\n    public int longestAwesome(String s) {\n        int n = s.length();\n        int[] preSum = new int[1 << 9 + 1];\n        Arrays.fill(preSum, n);\n        preSum[0] = -1;\n        int res = 0;\n        int mask = 0;\n        for (int i = 0; i < n; i++) {\n            char c = s.charAt(i);\n            mask ^= 1 << (c - \'0\');\n            res = Math.max(res, i - preSum[mask]);\n            for (int j = 0; j < 10; j++) {\n                res = Math.max(res, i - preSum[mask ^ (1 << j)]);\n            }\n            if (preSum[mask] == n) preSum[mask] = i;\n        }\n        return res;\n    }\n}\n```
['Java']