• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Uriel's Corner

            Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
            posts - 0, comments - 50, trackbacks - 0, articles - 594
            類似208,Trie樹操作,注意本題存在通配符'.',所以search操作需要DFS實現(xiàn)


             1 #211
             2 #Runtime: 10694 ms (Beats 62.94%)
             3 #Memory: 119.7 MB (Beats 22.35%)
             4 
             5 class TrieNode:
             6     def __init__(self):
             7         self.sons = {}
             8         self.eow = False
             9 
            10 
            11 class WordDictionary(object):
            12 
            13     def __init__(self):
            14         self.root = TrieNode()
            15 
            16     def addWord(self, word):
            17         """
            18         :type word: str
            19         :rtype: None
            20         """
            21         r = self.root
            22         for ch in word:
            23             if ch not in r.sons:
            24                 r.sons[ch] = TrieNode()
            25             r = r.sons[ch]
            26         r.eow = True
            27         
            28 
            29     def search(self, word):
            30         """
            31         :type word: str
            32         :rtype: bool
            33         """
            34         def DFS(r, depth):
            35             if depth == len(word):
            36                 return r.eow
            37             if word[depth] == '.':
            38                 for ch in r.sons:
            39                     if DFS(r.sons[ch], depth + 1):
            40                         return True
            41             if word[depth] in r.sons:
            42                 return DFS(r.sons[word[depth]], depth + 1)
            43             return False
            44         return DFS(self.root, 0)
            45         
            46 
            47 
            48 # Your WordDictionary object will be instantiated and called as such:
            49 # obj = WordDictionary()
            50 # obj.addWord(word)
            51 # param_2 = obj.search(word)
            精品熟女少妇aⅴ免费久久| 久久精品国产日本波多野结衣| 国内精品久久久久影院亚洲| 亚洲中文久久精品无码ww16| 国产韩国精品一区二区三区久久 | 国产Av激情久久无码天堂| 2021国产精品久久精品| 一本色道久久88综合日韩精品| 91视频国产91久久久| 亚洲精品美女久久久久99| 精品无码久久久久国产| 99久久精品这里只有精品| 狠狠色丁香婷婷久久综合| 天天影视色香欲综合久久| 久久无码人妻精品一区二区三区| 精品免费久久久久久久| 亚洲精品无码久久不卡| 少妇人妻综合久久中文字幕| 日韩精品久久久久久久电影蜜臀| 久久精品无码一区二区三区| 99精品伊人久久久大香线蕉| 亚洲狠狠婷婷综合久久久久| 日韩AV毛片精品久久久| 亚洲精品高清国产一线久久| 午夜不卡888久久| 99久久精品日本一区二区免费| 久久99精品久久久久久齐齐| 国产精品久久久亚洲| 热99re久久国超精品首页| 久久婷婷久久一区二区三区| 久久国产成人精品麻豆| 国产亚洲欧美成人久久片| 99久久精品免费看国产一区二区三区| 麻豆国内精品久久久久久| 久久99热国产这有精品| 久久久噜噜噜久久| 久久天天躁狠狠躁夜夜2020| 亚洲综合久久久| 浪潮AV色综合久久天堂| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 国产精品欧美久久久久无广告 |