• <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)
            久久综合狠狠色综合伊人| 久久无码国产| 91精品国产高清久久久久久io| www.久久热| 久久综合给合综合久久| 亚洲精品乱码久久久久久| .精品久久久麻豆国产精品| 久久婷婷五月综合成人D啪| 亚洲AV日韩精品久久久久| 久久精品国产一区二区三区日韩| 久久无码精品一区二区三区| 久久国产精品无码HDAV| 色8激情欧美成人久久综合电| 99久久婷婷国产综合亚洲| 一日本道伊人久久综合影| 久久久91精品国产一区二区三区| 亚洲AⅤ优女AV综合久久久| 欧美精品一区二区精品久久| 亚洲精品无码久久一线| 久久久久亚洲av毛片大| 国产成人精品久久亚洲高清不卡| 久久久免费精品re6| 一本久道久久综合狠狠爱| 欧美成a人片免费看久久| 色综合久久久久网| 精品久久香蕉国产线看观看亚洲| 精品伊人久久久| 久久婷婷五月综合色99啪ak| 91精品国产91久久| 久久免费视频观看| 99国产欧美精品久久久蜜芽| 亚洲欧美成人综合久久久| 少妇人妻综合久久中文字幕| 亚洲综合久久夜AV | 中文字幕无码久久人妻| 久久久久久久91精品免费观看| 久久se精品一区二区影院| 久久亚洲高清综合| 亚洲Av无码国产情品久久| 久久人人爽人人爽人人片AV不| 久久亚洲国产精品成人AV秋霞|