Keyboard Row Python Solution


  • 0
    P

    class Solution(object):
    def findWords(self, words):
    """
    :type words: List[str]
    :rtype: List[str]
    """
    rowone = ['q','w','e','r','t','y','u','i','o','p']
    rowtwo = ['a','s','d','f','g','h','j','k','l']
    List = []
    for word in words:
    flag1 = 0
    flag2 = 0
    flag3 = 0
    for char in word:
    if char.lower() in rowone:
    flag1 = 1
    elif char.lower() in rowtwo:
    flag2 = 1
    else:
    flag3 = 1
    if (flag1+flag2+flag3)<=1:
    List.append(word)
    return List


Log in to reply
 

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