forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1684.java
29 lines (27 loc) · 827 Bytes
/
_1684.java
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
package com.fishercoder.solutions;
import java.util.HashSet;
import java.util.Set;
public class _1684 {
public static class Solution1 {
public int countConsistentStrings(String allowed, String[] words) {
Set<Character> set = new HashSet<>();
for (char c : allowed.toCharArray()) {
set.add(c);
}
int count = 0;
for (String word : words) {
boolean isConsistent = true;
for (char c : word.toCharArray()) {
if (!set.contains(c)) {
isConsistent = false;
break;
}
}
if (isConsistent) {
count++;
}
}
return count;
}
}
}