• <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)
            久久精品中文騷妇女内射| 亚洲精品无码久久久久sm| 国产成人久久777777| 久久99亚洲综合精品首页| 久久SE精品一区二区| 久久亚洲综合色一区二区三区| 欧美伊人久久大香线蕉综合69| 无码人妻精品一区二区三区久久久| 久久国产成人| 九九99精品久久久久久| 伊人情人综合成人久久网小说| 国产成人精品久久二区二区| 久久久久久久久久久| 久久久久噜噜噜亚洲熟女综合| 丰满少妇高潮惨叫久久久| 久久国产欧美日韩精品| 久久天天躁狠狠躁夜夜2020老熟妇| 久久超乳爆乳中文字幕| 综合网日日天干夜夜久久| 蜜臀久久99精品久久久久久| 免费国产99久久久香蕉| 高清免费久久午夜精品| 久久亚洲精品成人AV| 亚洲精品无码久久久久去q| 波多野结衣久久一区二区| 欧美亚洲日本久久精品| 欧美国产成人久久精品| 久久亚洲国产成人影院网站| 久久99精品免费一区二区| 国产精品激情综合久久| 国产精品欧美亚洲韩国日本久久| 久久国产乱子伦精品免费强| 66精品综合久久久久久久| 久久免费精品视频| 久久99国产精品99久久| 伊人久久综在合线亚洲2019| 91精品国产综合久久香蕉| 国产精品九九久久免费视频| 久久99热这里只有精品国产| 伊人久久大香线蕉综合网站| 狠狠精品久久久无码中文字幕 |