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.
Input: ["Hello", "Alaska", "Dad", "Peace"] Output: ["Alaska", "Dad"]
- You may use one character in the keyboard more than once.
- You may assume the input string will only contain letters of alphabet.
class Solution:
def findWords(self, words: List[str]) -> List[str]:
result = []
row_q = set("qwertyuiop")
row_a = set("asdfghjkl")
row_z = set("zxcvbnm")
for word in words:
word_set = set(word.lower())
if word_set <= row_q or word_set <= row_a or word_set <= row_z:
result.append(word)
return result