首页 > 学院 > 开发设计 > 正文

500. Keyboard Row (E)

2019-11-08 01:05:29
字体:
来源:转载
供稿:网友

Given a List of Words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.

American keyboard

Example 1:

Input: ["Hello", "Alaska", "Dad", "Peace"]Output: ["Alaska", "Dad"]

Note:

You may use one character in the keyboard more than once.You may assume the input string will only contain letters of alphabet.

Subscribe to see which companies asked this question.

My Rex Solution:

public class Solution {    public String[] findWords(String[] words) {        List<String> data=new ArrayList<String>();        for(String s:words){            if(s.toLowerCase().matches("([qwertyuiop]+)|([asdfghjkl]+)|([zxcvbnm]+)"))                data.add(s);        }        String[] re=new String[data.size()];        for(int i=0;i<data.size();++i)            re[i]=data.get(i);        return re;        }}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表