Maximum Number of Words You Can Type
给一个string和一个char数组, 表示坏的键盘的字符, 问能组成几个string的word.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
class Solution { public int canBeTypedWords(String text, String brokenLetters) { String[] strs = text.split(" "); int res = 0; Set<Character> set = new HashSet<>(); for(char c : brokenLetters.toCharArray()) set.add(c); for(String s : strs){ boolean add = true; for(char c : s.toCharArray()) if(set.contains(c)){ add = false; break; } if(add) res++; } return res; } } |