• <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)
            精品久久8x国产免费观看| 精品久久久无码人妻中文字幕豆芽| 国产福利电影一区二区三区久久久久成人精品综合 | 国产精品久久久久影视不卡| 99久久99久久| 无码人妻久久一区二区三区蜜桃| 亚洲欧美成人综合久久久| 99久久国产综合精品五月天喷水| 中文字幕精品久久| 国产精品久久99| 要久久爱在线免费观看| 国产精品久久毛片完整版| 久久精品国产亚洲5555| 亚洲AV无码1区2区久久| 久久久久这里只有精品| 久久99精品久久久久子伦| 久久99精品免费一区二区 | 无码人妻久久一区二区三区蜜桃| 国内精品九九久久久精品| 久久久久国产日韩精品网站| 伊人久久精品线影院| 伊人久久无码中文字幕| 久久精品国产亚洲Aⅴ香蕉| 国内精品人妻无码久久久影院| 婷婷久久综合| 久久99精品免费一区二区| 精品人妻久久久久久888| 久久精品无码一区二区WWW| 欧美与黑人午夜性猛交久久久 | 精品99久久aaa一级毛片| 国产美女久久精品香蕉69| 亚洲AV乱码久久精品蜜桃| 久久久久国产精品人妻| 亚洲国产成人精品无码久久久久久综合| 97久久天天综合色天天综合色hd| 亚洲精品无码成人片久久| 2021国内久久精品| 久久久国产打桩机| 无码人妻久久一区二区三区| 亚洲精品无码久久一线| 久久精品麻豆日日躁夜夜躁|