-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeetcode_1684.java
38 lines (31 loc) · 1.3 KB
/
Leetcode_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
30
31
32
33
34
35
36
37
38
class Solution {
public int countConsistentStrings(String allowed, String[] words) {
int consistentCount = 0;
// Iterate through each word in the words array
for (String word : words) {
boolean isWordConsistent = true;
// Check each character in the current word
for (int i = 0; i < word.length(); i++) {
char currentChar = word.charAt(i);
boolean isCharAllowed = false;
// Check if the current character is in the allowed string
for (int j = 0; j < allowed.length(); j++) {
if (allowed.charAt(j) == currentChar) {
isCharAllowed = true;
break; // Character found, no need to continue searching
}
}
// If the character is not allowed, mark the word as inconsistent
if (!isCharAllowed) {
isWordConsistent = false;
break; // No need to check remaining characters
}
}
// If the word is consistent, increment the count
if (isWordConsistent) {
consistentCount++;
}
}
return consistentCount;
}
}