[Java} Share my 2 ms solution with bitMap
The intuition is that since we only care about 26 letters, we can simply use an integer as a set.\nIf we take bitwise and between two integers, we will get 0 if
The intuition is that since we only care about 26 letters, we can simply use an integer as a set.\nIf we take bitwise and between two integers, we will get 0 if there is no duplicate.\nAlso, we can just use bitwise OR to combine the previous strings. \nBy this trick, we can avoid string add operation as well as faster inquiry for if all characters in current string is unique. \n```\nclass Solution {\n    public int maxLength(List<String> arr) {\n        int n = arr.size();\n        int[] ans = new int[1];\n        int[][] bitMap = new int[n][2];\n        for (int i = 0; i < n; ++i) {\n            int a = 0;\n            for (char ch: arr.get(i).toCharArray()) {\n                int bit = ch - \'a\';\n                if (((a >> bit) & 1) == 1) {\n                    a = 0;\n                    break;\n                }\n                a |= (1 << bit);\n            }\n            bitMap[i][0] = a;\n            bitMap[i][1] = a == 0 ? 0 : arr.get(i).length();\n        }\n        dfs(arr, bitMap, ans, 0, 0, 0);\n        return ans[0];\n    }\n    \n    private void dfs(List<String> arr, int[][] bitMap, int[] ans, int start, int curLen, int curBit) {\n        if (ans[0] < curLen) ans[0] = curLen;\n        for (int i = start; i < arr.size(); ++i) {\n            if ((curBit & bitMap[i][0]) != 0) continue;\n            dfs(arr, bitMap, ans, i + 1, curLen + bitMap[i][1], curBit | bitMap[i][0]);\n        }\n    }\n}\n```
[]