/*
* @lc app=leetcode.cn id=1684 lang=typescript
*
* [1684] 统计一致字符串的数目
*/
// @lc code=start
function countConsistentStrings(allowed: string, words: string[]): number {}
// @lc code=end
function countConsistentStrings(allowed: string, words: string[]): number {
let res = 0,
set = new Set(allowed)
next: for (let word of words) {
for (let ch of word) if (!set.has(ch)) continue next
res++
}
return res
}
test.each([
{ input: { allowed: 'ab', words: ['ad', 'bd', 'aaab', 'baa', 'badab'] }, output: 2 },
{ input: { allowed: 'abc', words: ['a', 'b', 'c', 'ab', 'ac', 'bc', 'abc'] }, output: 7 },
{ input: { allowed: 'cad', words: ['cc', 'acd', 'b', 'ba', 'bac', 'bad', 'ac', 'd'] }, output: 4 },
])('input: allowed = $input.allowed, words = $input.words', ({ input: { allowed, words }, output }) => {
expect(countConsistentStrings(allowed, words)).toEqual(output)
})