• <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)
            久久综合狠狠色综合伊人| 久久精品中文字幕一区| 精品综合久久久久久97超人| 国产成人久久精品区一区二区| 久久A级毛片免费观看| 99久久亚洲综合精品成人| 亚洲国产成人精品女人久久久 | 天天久久狠狠色综合| 久久se精品一区二区影院 | 国产精品久久久久蜜芽| 久久国产热精品波多野结衣AV| 国产三级精品久久| 72种姿势欧美久久久久大黄蕉| 亚洲国产成人精品女人久久久 | 三级片免费观看久久| 99久久精品免费| 久久天天躁狠狠躁夜夜躁2O2O| 精品久久久久久无码国产| 久久精品99久久香蕉国产色戒| 久久天天躁狠狠躁夜夜躁2014 | 伊人久久大香线蕉综合Av | 色欲久久久天天天综合网 | 久久久这里有精品中文字幕| 无码超乳爆乳中文字幕久久| 亚洲国产精品综合久久一线| 日本道色综合久久影院| 久久精品夜夜夜夜夜久久| 精品久久久久久无码不卡| 国产一区二区精品久久凹凸| 久久综合九色综合97_久久久| 亚洲AV日韩精品久久久久久| 青青草原综合久久大伊人| 久久青青国产| 欧美精品丝袜久久久中文字幕| 99久久综合狠狠综合久久| 青草影院天堂男人久久| 国产99久久精品一区二区| 久久久久综合网久久| 97超级碰碰碰碰久久久久| 久久综合久久鬼色| 日韩欧美亚洲综合久久影院Ds|