Question about unique characters note


  • 0
    K

    I have a question about the note "You may use one character in the keyboard more than once." I am assuming this means per word that we analyze?

    I ran my solution and get these test results:

    Input: ["qz","wq","asdddafadsfa","adfadfadfdassfawde"]
    Output: ["wq"]
    Expected: ["wq","asdddafadsfa"]

    Shouldn't the word "asdddafadsfa" not be allowed because more than one letter appears multiple times?

    Also, I know this isn't the most efficient and clean way to do this, but here is my code:

    class Solution(object):
        def findWords(self, words):
            """
            :type words: List[str]
            :rtype: List[str]
            """
         
            kb_rows = ['qwertyuiop','asdfghjkl','zxcvbnm']
            result = []
            for w in words:
                l_dict = {}
                
                found_dupe = []
                for l in w.lower():
                    
                    if l in l_dict:
                        if l not in found_dupe:
                            found_dupe.append(l)
                            if len(found_dupe) > 1:
                                break
                        l_dict[l] += 1
                    else: 
                        l_dict[l] = 1
               
                if len(found_dupe) > 1:
                    continue
           
                for r in kb_rows:
                    all_in_row = True
                    for k in l_dict.keys():
                        if k not in r:
                            all_in_row = False
                            break
                    
                    if all_in_row:
                        result.append(w)
                        break
            
            return result
    

Log in to reply
 

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