标签:nbsp http result bubuko etc row size key ++
class Solution { public String[] findWords(String[] words) { HashSet<Character>[] rows = new HashSet[3]; ArrayList<String> result = new ArrayList<>(); String[] letters = {"qwertyuiopQWERTYUIOP","asdfghjklASDFGHJKL","zxcvbnmZXCVBNM"}; for(int i=0;i<3;i++) { rows[i] = new HashSet<Character>(); //这里容易忽略从而报错nullPointerException char[] temp = letters[i].toCharArray(); for(char l:temp) rows[i].add(l); } for(String word:words) { char[] ls = word.toCharArray(); int row; for(row=0;row<3;row++) if(rows[row].contains(ls[0])) break; boolean isOK = true; for(char l:ls) if(!rows[row].contains(l)) {isOK=false;break;} if(isOK) result.add(word); } String[] r = new String[result.size()]; for(int i=0;i<r.length;i++) { r[i]=result.get(i); } return r; } }
标签:nbsp http result bubuko etc row size key ++
原文地址:https://www.cnblogs.com/chason95/p/9291277.html