LeetCode500. Keyboard Row(ArrayL
2017-02-13 本文已影响0人
Yuu_CX
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报错,必须转化下
}
}