Skip to content

Commit 0916aad

Browse files
Add files via upload
1 parent a318e4f commit 0916aad

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution {
2+
public int solve(String strs[], int no, int a[], int index, int c) {
3+
if(index==c)
4+
return 0;
5+
int x=no & a[index];
6+
if(x==0)
7+
return Math.max(strs[index].length()+solve(strs,no^a[index],a,index+1,c),solve(strs,no,a,index+1,c));
8+
else
9+
return solve(strs,no,a,index+1,c);
10+
}
11+
public int maxLength(List<String> arr) {
12+
int a[]=new int[arr.size()];int c=0;String strs[]=new String[a.length];
13+
for(String s:arr) {
14+
int x=0,fl=0;
15+
for(char ch:s.toCharArray())
16+
{
17+
int z=x|(1<<(ch-96));
18+
if(x==z)
19+
{
20+
fl=1;break;
21+
}
22+
x=z;
23+
}
24+
if(fl==0)
25+
{
26+
a[c]=x;
27+
strs[c++]=s;
28+
}
29+
}
30+
return solve(strs,0,a,0,c);
31+
}
32+
}

0 commit comments

Comments
 (0)