File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,471 LeetCode solutions in JavaScript
1
+ # 1,472 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1296
1296
1679|[ Max Number of K-Sum Pairs] ( ./solutions/1679-max-number-of-k-sum-pairs.js ) |Medium|
1297
1297
1680|[ Concatenation of Consecutive Binary Numbers] ( ./solutions/1680-concatenation-of-consecutive-binary-numbers.js ) |Medium|
1298
1298
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|
1299
1300
1716|[ Calculate Money in Leetcode Bank] ( ./solutions/1716-calculate-money-in-leetcode-bank.js ) |Easy|
1300
1301
1718|[ Construct the Lexicographically Largest Valid Sequence] ( ./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js ) |Medium|
1301
1302
1726|[ Tuple with Same Product] ( ./solutions/1726-tuple-with-same-product.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments