type
status
date
slug
summary
tags
category
icon
password
题目:
给你一个由不同字符组成的字符串
allowed
和一个字符串数组 words
。如果一个字符串的每一个字符都在 allowed
中,就称这个字符串是 一致字符串 。请你返回
words
数组中 一致字符串 的数目。来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/SNJvJP 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
示例 1:
示例 2:
示例 3:
提示:
1 <= words.length <= 104
1 <= allowed.length <= 26
1 <= words[i].length <= 10
allowed
中的字符 互不相同 。
words[i]
和allowed
只包含小写英文字母。
思路:
- 对字符串进行遍历
- 对allowed进行遍历
- 满足一个flag++
- 内层循环跳出后,判断flag
- flag为0,返回false
代码:
结果:

image-20220225235539604