美文网首页
LeetCode500. Keyboard Row(ArrayL

LeetCode500. Keyboard Row(ArrayL

作者: Yuu_CX | 来源:发表于2017-02-13 20:27 被阅读0次
    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报错,必须转化下
        }
    }
    

    相关文章

      网友评论

          本文标题:LeetCode500. Keyboard Row(ArrayL

          本文链接:https://www.haomeiwen.com/subject/dautwttx.html