• <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)
            精品久久久久久久久中文字幕| 久久久久亚洲AV无码去区首| 久久只有这精品99| 亚洲欧美一区二区三区久久| 久久人人爽人人爽人人片AV不 | 成人精品一区二区久久久| 狠狠精品久久久无码中文字幕 | 久久久亚洲欧洲日产国码aⅴ | 久久国产香蕉一区精品| 久久综合亚洲鲁鲁五月天| 国产精品99久久久久久人| 亚洲精品成人网久久久久久| 97久久精品无码一区二区| 久久精品免费网站网| 精品乱码久久久久久久| 亚洲第一永久AV网站久久精品男人的天堂AV | 狠狠狠色丁香婷婷综合久久五月 | 亚洲中文字幕无码久久综合网| 久久免费线看线看| 午夜精品久久久久久久久| 国产精品一区二区久久精品无码| 亚洲AV无码久久精品狠狠爱浪潮| 国产视频久久| 久久99免费视频| 国产一级做a爰片久久毛片| 久久精品国产乱子伦| 久久综合久久鬼色| 久久99热这里只有精品国产 | 色偷偷88888欧美精品久久久| 久久青青草原精品国产不卡| 国产精品亚洲美女久久久| 情人伊人久久综合亚洲| 99久久国产综合精品麻豆| 久久99国产综合精品免费| 久久精品国产亚洲AV无码偷窥| 无码国内精品久久人妻| 久久久久亚洲AV成人网人人网站 | 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 亚洲欧美成人久久综合中文网 | 久久久久AV综合网成人| 日韩精品久久无码中文字幕|