Swift, bit mask and dictionary
Intuition\nwe use a mask to track the number of each digit we have seen. For example, if we have seen an even number of digit 7, we would set 0 in the 7th bit p
# Intuition\nwe use a mask to track the number of each digit we have seen. For example, if we have seen an even number of digit 7, we would set 0 in the 7th bit position in the mask, otherwise we set it to 1.\nWe also use a dictionary to track the first position we have seen this mask.\nThen we use bit manipulation to test if there exist a subarray that has only one single digit, or no single digit.\n\n# Code\n```\nclass Solution {\n    func longestAwesome(_ s: String) -> Int {\n        let s = Array(s)\n        var visited = [Int: Int]()\n        visited[0] = -1\n        var mask = 0\n        var res = 0\n        for i in 0..<s.count {\n            let c = s[i]\n            let bit = c.asciiValue! - Character("0").asciiValue!\n            mask ^= 1 << bit\n            for (old_mask, index) in visited {\n                var diff = mask ^ old_mask\n                if diff == 0 || ((diff & (diff - 1)) == 0) {\n                    res = max(i - index, res)\n                }\n            }\n            if visited[mask] == nil {\n                visited[mask] = i\n            }\n        }\n        return res\n    }\n}\n```
['Swift']