We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 47aabc6 commit 8b80547Copy full SHA for 8b80547
scripts/algorithms/C/Count the Number of Consistent Strings/Count the Number of Consistent Strings.java
@@ -1,22 +1,23 @@
1
+// Runtime: 15 ms (Top 73.10%) | Memory: 54.7 MB (Top 46.20%)
2
class Solution {
3
public int countConsistentStrings(String allowed, String[] words) {
4
Set<Character> allowedSet = new HashSet<>();
5
for(int i=0;i<allowed.length();i++){
6
allowedSet.add(allowed.charAt(i));
7
}
-
8
+
9
int count = 0;
10
for(String word: words){
11
if(isConsistent(allowedSet, word)) count++;
12
13
14
return count;
15
16
17
boolean isConsistent(Set<Character> allowedSet, String word){
18
for (int i = 0; i < word.length(); i++){
- if(!allowedSet.contains(word.charAt(i))) return false;
19
+ if(!allowedSet.contains(word.charAt(i))) return false;
20
21
return true;
22
-}
23
+}
0 commit comments