• <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
            實現(xiàn)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)
            久久人人爽人人爽人人AV东京热| 色婷婷综合久久久久中文 | 色偷偷88888欧美精品久久久| 国产精品久久婷婷六月丁香| 亚洲愉拍99热成人精品热久久| 久久91精品国产91久久小草| 日韩精品久久久久久| 伊人久久国产免费观看视频| 久久精品亚洲一区二区三区浴池| 国产免费久久精品丫丫| AV无码久久久久不卡蜜桃| 亚洲国产精品久久久久婷婷老年| 亚洲精品第一综合99久久| 99久久精品国产高清一区二区 | 久久99精品久久久久久| 人妻中文久久久久| 青青草原综合久久| 色偷偷久久一区二区三区| 激情五月综合综合久久69| 久久久精品2019免费观看| 中文字幕久久精品| 久久综合九色欧美综合狠狠| 九九精品99久久久香蕉| 久久久久久综合网天天| 久久免费99精品国产自在现线| 1000部精品久久久久久久久| 久久久久亚洲AV无码专区首JN| 精品99久久aaa一级毛片| 国产∨亚洲V天堂无码久久久| 久久乐国产综合亚洲精品| 久久黄色视频| 久久久久久久综合日本| 99久久精品免费国产大片| 久久精品亚洲一区二区三区浴池 | 四虎国产精品免费久久久| 久久久久高潮毛片免费全部播放| 久久亚洲国产精品成人AV秋霞| 一本色综合久久| 99精品国产99久久久久久97| 国产精品久久久久久久久软件| 婷婷久久五月天|