Keyboard Row

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:

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

Note:

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

Solution

水题,看懂题意就能做出来了,判断单词能不能用键盘上一行打出

Python

1
2
3
4
5
6
7
class Solution(object):
def findWords(self, words):
"""
:type words: List[str]
:rtype: List[str]
"""
return filter(re.compile('(?i)([qwertyuiop]*|[asdfghjkl]*|[zxcvbnm]*)$').match, words)