题目简介:
给你一个由不同字符组成的字符串 allowed 和一个字符串数组 words 。如果一个字符串的每一个字符都在 allowed 中,就称这个字符串是 一致字符串 。
请你返回 words 数组中 一致字符串 的数目。
示例 1:
1 | 输入:allowed = "ab", words = ["ad","bd","aaab","baa","badab"] |
提示:
1 <= words.length <= 10^41 <= allowed.length <= 261 <= words[i].length <= 10allowed中的字符 互不相同 。words[i]和allowed只包含小写英文字母。
思路:
利用哈希表存储allowed,再依次遍历字符串即可
代码如下:
1 | class Solution { |