My python solution 35ms(92.93%)


  • 0
    Y
    class Solution(object):
        def findWords(self, words):
            """
            :type words: List[str]
            :rtype: List[str]
            """
            row1 = 'qwertyuiopQWERTYUIOP'
            row2 = 'asdfghjklASDFGHJKL'
            row3 = 'zxcvbnmZXCVBNM'
            
            res = []
            for word in words:
                tmp=[]
                for w in word:
                    if w in row1:
                        tmp.append(1)
                    elif w in row2:
                        tmp.append(2)
                    elif w in row3:
                        tmp.append(3)
                if len(set(tmp))==1:
                    res.append(word)
            return res
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.