• <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實現


             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)
            亚洲人成电影网站久久| 久久精品国产亚洲沈樵| 日本加勒比久久精品| 亚洲?V乱码久久精品蜜桃| 欧美日韩精品久久久免费观看 | 浪潮AV色综合久久天堂| 欧美精品一区二区精品久久| 中文字幕无码av激情不卡久久| 影音先锋女人AV鲁色资源网久久 | 精品久久久久久久久久中文字幕| 亚洲国产成人久久综合野外| 久久99精品国产99久久| 亚洲AV成人无码久久精品老人| 久久国产乱子精品免费女| 亚洲中文久久精品无码ww16| 久久99久久无码毛片一区二区| 色偷偷88888欧美精品久久久| 久久人妻少妇嫩草AV蜜桃| 99精品国产在热久久无毒不卡 | 国内精品久久九九国产精品| 精品久久亚洲中文无码| 欧美激情精品久久久久久久九九九| 麻豆成人久久精品二区三区免费 | 亚洲乱码日产精品a级毛片久久| 91视频国产91久久久| 狼狼综合久久久久综合网| 色诱久久av| 久久影院午夜理论片无码| 国产午夜精品久久久久九九电影| 91精品国产高清91久久久久久| 7777久久久国产精品消防器材| 久久国产免费直播| 亚洲精品美女久久久久99| 欧美亚洲国产精品久久| 中文无码久久精品| 久久人人妻人人爽人人爽| 看久久久久久a级毛片| 国产精品久久久久影院色 | 久久综合亚洲鲁鲁五月天| 欧美色综合久久久久久| 中文字幕精品无码久久久久久3D日动漫 |