leetcode 500. 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.

Exmaple:

Input: [“Hello”, “Alaska”, “Dad”, “Peace”]
Output: [“Alaska”, “Dad”]

关于解法

  1. 这道题用python还是很方便的,用一行写完
1
2
3
4
5
6
7
8
class Solution(object):
def findWords(self, words):
"""
:type words: List[str]
:rtype: List[str]
"""
judge = lambda x : sum(set(x.lower()).issubset(r) for r in [set(r) for r in ["qwertyuiop","asdfghjkl","zxcvbnm"]])
return filter(judge,words)