Count the Number of Consistent Strings LeetCode solution in JavaScript

1
/**
2
* @param {string} allowed
3
* @param {string[]} words
4
* @return {number}
5
*/
6
var countConsistentStrings = function (allowed, words) {
7
const hashmap = new Map();
8
let output = 0;
9

10
for (let i = 0; i < allowed.length; i++) {
11
hashmap.set(allowed[i], 1);
12
}
13

14
for (let i = 0; i < words.length; i++) {
15
const word = words[i];
16
output++;
17
for (let j = 0; j < word.length; j++) {
18
if (!hashmap.has(word[j])) {
19
output--;
20
break;
21
}
22
}
23
}
24

25
return output;
26
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0