Count the Number of Consistent Strings LeetCode solution in Java

1
class Solution {
2
public int countConsistentStrings(String allowed, String[] words) {
3
Set<Character> allowedSet = new HashSet<>();
4
for (int i = 0; i < allowed.length(); i++) {
5
allowedSet.add(allowed.charAt(i));
6
}
7

8
int count = 0;
9
for (String word : words) {
10
if (isConsistent(allowedSet, word)) count++;
11
}
12

13
return count;
14
}
15

16
boolean isConsistent(Set<Character> allowedSet, String word) {
17
for (int i = 0; i < word.length(); i++) {
18
if (!allowedSet.contains(word.charAt(i))) return false;
19
}
20
return true;
21
}
22
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0