classSolution:defgetValidT9Words(self, num:str, words: List[str])-> List[str]:
kb ={'2':'abc','3':'def','4':'ghi','5':'jkl','6':'mno','7':'pqrs','8':'tuv','9':'wxyz'}
ns =list(num)
candidate = words
for i, n inenumerate(ns):
candidate =[w for w in candidate if w[i]in kb[n]]return candidate
classSolution:defgetValidT9Words(self, num:str, words: List[str])-> List[str]:
ans =list()
arr =['2','2','2','3','3','3','4','4','4','5','5','5','6','6','6','7','7','7','7','8','8','8','9','9','9','9']for word in words:
index =0
flag =Truefor c in word:if num[index]== arr[ord(c)-ord('a')]:
index +=1else:
flag =Falsebreakif flag: ans.append(word)return ans