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.
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; }}
新闻热点
疑难解答