-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountConsistentStrings.java
More file actions
32 lines (26 loc) · 1.03 KB
/
CountConsistentStrings.java
File metadata and controls
32 lines (26 loc) · 1.03 KB
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
public class CountConsistentStrings {
static int countConsistentStrings(String allowed, String[] words) {
char[] ch = allowed.toCharArray();
int sum = 0;
for (int i = 0; i < words.length; i++) {
char[] fromArray = words[i].toCharArray();
for (int x = 0; x < fromArray.length; x++) {
for (int y = 0; y < ch.length; y++) {
if (fromArray[x] == ch[y] && x != fromArray.length - 1) {
break;
} else if (fromArray[x] == ch[y] && x == fromArray.length - 1) {
sum++;
} else if (fromArray[x] != ch[y] && y == ch.length - 1) {
x = fromArray.length - 1;
}
}
}
}
return sum;
}
public static void main(String[] args) {
String[] words = {"a","b","c","ab","ac","bc","abc"};
String allowed = "abc";
System.out.println(countConsistentStrings(allowed, words));
}
}