Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 998d615

Browse files
committed
Add solution #1684
1 parent 0cc1e49 commit 998d615

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,471 LeetCode solutions in JavaScript
1+
# 1,472 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1296,6 +1296,7 @@
12961296
1679|[Max Number of K-Sum Pairs](./solutions/1679-max-number-of-k-sum-pairs.js)|Medium|
12971297
1680|[Concatenation of Consecutive Binary Numbers](./solutions/1680-concatenation-of-consecutive-binary-numbers.js)|Medium|
12981298
1681|[Minimum Incompatibility](./solutions/1681-minimum-incompatibility.js)|Hard|
1299+
1684|[Count the Number of Consistent Strings](./solutions/1684-count-the-number-of-consistent-strings.js)|Easy|
12991300
1716|[Calculate Money in Leetcode Bank](./solutions/1716-calculate-money-in-leetcode-bank.js)|Easy|
13001301
1718|[Construct the Lexicographically Largest Valid Sequence](./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js)|Medium|
13011302
1726|[Tuple with Same Product](./solutions/1726-tuple-with-same-product.js)|Medium|
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* 1684. Count the Number of Consistent Strings
3+
* https://leetcode.com/problems/count-the-number-of-consistent-strings/
4+
* Difficulty: Easy
5+
*
6+
* You are given a string allowed consisting of distinct characters and an array of strings words.
7+
* A string is consistent if all characters in the string appear in the string allowed.
8+
*
9+
* Return the number of consistent strings in the array words.
10+
*/
11+
12+
/**
13+
* @param {string} allowed
14+
* @param {string[]} words
15+
* @return {number}
16+
*/
17+
var countConsistentStrings = function(allowed, words) {
18+
const allowedSet = new Set(allowed);
19+
let result = 0;
20+
21+
for (const word of words) {
22+
let isConsistent = true;
23+
for (const char of word) {
24+
if (!allowedSet.has(char)) {
25+
isConsistent = false;
26+
break;
27+
}
28+
}
29+
if (isConsistent) result++;
30+
}
31+
32+
return result;
33+
};

0 commit comments

Comments
 (0)