public class Solution {
public String[] findWords(String[] words) {
String regex="[qwertyuiop]*|[asdfghjkl]*|[zxcvbnm]*";
String a;
ArrayList<String> list = new ArrayList<>();
for(int i=0;i<words.length;i++){
a = words[i].toLowerCase();
if(a.matches(regex)) list.add(words[i]);
}
return list.toArray(new String[0]);//若直接返回list报错,必须转化下
}
}
网友评论