Skip to content

Commit ecda9e4

Browse files
add 1684
1 parent 9b4614e commit ecda9e4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1684|[Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1684.java) ||Easy|String|
1112
|1679|[Max Number of K-Sum Pairs](https://leetcode.com/problems/max-number-of-k-sum-pairs/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1679.java) ||Medium|HashTable|
1213
|1678|[Goal Parser Interpretation](https://leetcode.com/problems/goal-parser-interpretation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1678.java) ||Easy|String|
1314
|1673|[Find the Most Competitive Subsequence](https://leetcode.com/problems/find-the-most-competitive-subsequence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1673.java) ||Medium|Stack, Greedy|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class _1684 {
7+
public static class Solution1 {
8+
public int countConsistentStrings(String allowed, String[] words) {
9+
Set<Character> set = new HashSet<>();
10+
for (char c : allowed.toCharArray()) {
11+
set.add(c);
12+
}
13+
int count = 0;
14+
for (String word : words) {
15+
boolean isConsistent = true;
16+
for (char c : word.toCharArray()) {
17+
if (!set.contains(c)) {
18+
isConsistent = false;
19+
break;
20+
}
21+
}
22+
if (isConsistent) {
23+
count++;
24+
}
25+
}
26+
return count;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)