@ninijia 在 Leetcode每日一题练习 ------ 1684. 统计一致字符串的数目 中发帖
从Leetcode 每日一题练习继续讨论:
1684. 统计一致字符串的数目
1684. Count the Number of Consistent Strings
题解
本题是一道简单题, allowed中的字母均为不同字母, 则可用长度为26的布尔数组保存allowed中哪个字母出现过, 再遍历words数组, 对每个字符串进行遍历, 一旦出现过未在allowed中出现的字母则直接跳过, 遍历下一个字符串, 对符合要求的字符串进行计数.
代码
func countConsistentStrings(allowed string, words []string) int {
allow := make([]bool, 26)
for i,_ := range allowed{
allow[allowed[i]-'a'] = true
}
...