1268. Search Suggestions System

1268. Search Suggestions System

class Solution:
    def dfs(self,d):
        if len(self.tans)==3:return 
        for key in d:
            if key=='*':
                self.tans.append(d[key])
            else:
                self.dfs(d[key])
        
    def suggestedProducts(self, products: List[str], searchWord: str) -> List[List[str]]:
        products=sorted(products)
        mydict={}
        for product in products:
            d=mydict
            for c in product:
                if c not in d:
                    d[c]={}
                d=d[c]

            d['*']=product

        ans=[]
        d=mydict
        for c in searchWord:
            self.tans=[]
            # print(c,d)
            if c not in d:
                while len(ans)

你可能感兴趣的:(leetcode)