Skip to content

Commit 4e12d9b

Browse files
authored
Create Solution6.java
1 parent 7f6c417 commit 4e12d9b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Solution6.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution6 {
2+
public int maxLength(List<String> A) {
3+
List<Integer> dp = new ArrayList<>();
4+
dp.add(0);
5+
int res = 0;
6+
for (String s : A) {
7+
int a = 0, dup = 0;
8+
for (char c : s.toCharArray()) {
9+
dup |= a & (1 << (c - 'a'));
10+
a |= 1 << (c - 'a');
11+
}
12+
if (dup > 0) continue;
13+
for (int i = dp.size() - 1; i >= 0; --i) {
14+
if ((dp.get(i) & a) > 0) continue;
15+
dp.add(dp.get(i) | a);
16+
res = Math.max(res, Integer.bitCount(dp.get(i) | a));
17+
}
18+
}
19+
return res;
20+
}
21+
}

0 commit comments

Comments
 (0)