LeetCode 1684. 统计一致字符串的数目
解题思路
首先用set把allowed中的字符保存,然后一一判断。
相关代码
class Solution {public int countConsistentStrings(String allowed, String[] words) {Set<Character> set = new HashSet<>();int res=words.length;for(int i=0;i<allowed.length();i++) set.add(allowed.charAt(i));for(int j=0;j<words.length;j++){String word = words[j];for(int i=0;i<word.length();i++){if(set.contains(word.charAt(i))==false){res--;break;}}}return res;}
}