• <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
            實現Trie樹的三種操作:插入、查找是否包含某個單詞,以及是否包含某個前綴


             1 #208
             2 #Runtime: 184 ms (Beats 54.16%)
             3 #Memory: 40.8 MB (Beats 42.22%)
             4  
             5 class Node:
             6     def __init__(self):
             7         self.sons = {}
             8         self.eow = False
             9 
            10 
            11 class Trie(object):
            12 
            13     def __init__(self):
            14         self.root = Node()
            15 
            16 
            17     def insert(self, word):
            18         """
            19         :type word: str
            20         :rtype: None
            21         """
            22         r = self.root
            23         for ch in word:
            24             if ch not in r.sons:
            25                 r.sons[ch] = Node()
            26             r = r.sons[ch]
            27         r.eow = True
            28         
            29 
            30     def search(self, word):
            31         """
            32         :type word: str
            33         :rtype: bool
            34         """
            35         r = self.root
            36         for ch in word:
            37             if ch not in r.sons:
            38                 return False
            39             r = r.sons[ch]
            40         return r.eow
            41         
            42 
            43     def startsWith(self, prefix):
            44         """
            45         :type prefix: str
            46         :rtype: bool
            47         """
            48         r = self.root
            49         for ch in prefix:
            50             if ch not in r.sons:
            51                 return False
            52             r = r.sons[ch]
            53         return True
            54         
            55 
            56 
            57 # Your Trie object will be instantiated and called as such:
            58 # obj = Trie()
            59 # obj.insert(word)
            60 # param_2 = obj.search(word)
            61 # param_3 = obj.startsWith(prefix)
            国产∨亚洲V天堂无码久久久| 久久水蜜桃亚洲av无码精品麻豆| 国产69精品久久久久99| 久久精品国产亚洲一区二区三区| 久久综合九色综合欧美就去吻| 久久国产AVJUST麻豆| 国产成人精品免费久久久久| 久久国产成人| 久久国产精品久久精品国产| 亚洲欧美精品一区久久中文字幕| 欧美丰满熟妇BBB久久久| 久久精品国产亚洲Aⅴ香蕉| 久久99热只有频精品8| 久久这里有精品| 久久天天躁狠狠躁夜夜2020| 91久久婷婷国产综合精品青草| 国产精品亚洲综合久久| 久久久久亚洲精品男人的天堂 | 久久久久亚洲AV无码去区首| 97久久久精品综合88久久| 亚洲国产日韩综合久久精品| 中文字幕一区二区三区久久网站| 性做久久久久久久| 久久久久亚洲AV片无码下载蜜桃| 亚洲国产精品婷婷久久| 97久久精品无码一区二区天美| 国产成人精品综合久久久| 亚洲国产精品成人AV无码久久综合影院| 久久se精品一区精品二区| 久久精品中文字幕无码绿巨人| 久久精品国产乱子伦| 99久久精品免费看国产一区二区三区 | 久久精品中文闷骚内射| 久久se精品一区二区影院 | 欧美日韩精品久久久久| 久久夜色精品国产亚洲av| 久久亚洲天堂| 亚洲欧美日韩精品久久亚洲区 | 蜜桃麻豆www久久国产精品| www亚洲欲色成人久久精品| 国产成人精品久久亚洲高清不卡 |