-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI1.java
More file actions
33 lines (31 loc) · 881 Bytes
/
Copy pathI1.java
File metadata and controls
33 lines (31 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
public class I1 {
// "bella","label","roller"
public static List<String> commonChars(String[] words) {
HashSet<String> al = new HashSet<>();
int size = words[0].length();
char temp;
boolean fix;
int index = 0;
for(int i = 0 ; i < size ; i++){
temp = words[0].charAt(i);
fix = true;
for (String word : words) {
if (!word.contains(temp + "")) {
fix = false;
break;
}
}
if(fix){
al.add(temp+"");
}
}
return al.stream().toList();
}
public static void main(String[] args) {
String[] a = new String[]{"bella","label","roller"};
commonChars(a);
}
}