class Solution:
"""
@param words: a list of strings
@return: return a list of strings
"""
'''
大致思路:
1.初始化res = [],给出键盘的三个字符串,循环word,进行判断首位在哪个字符串,然后根据这个字符串进行循环,如果后面的字符都可以找到的话,则append到res里面。
'''
def findWords(self,words):
str1 = 'qwertyuiop'
str2 = 'asdfghjkl'
str3 = 'zxcvbnm'
str_w = ''
res = []
for word in words:
if word[0].lower() in str1:
str_w = str1
elif word[0].lower() in str2:
str_w = str2
else:
str_w = str3
if self.isRight(word,str_w) == True:
res.append(word)
return res
##单个word进行匹配
def isRight(self,word,str_w):
for i in word:
if i.lower() not in str_w:
return False
return True