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


             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高潮av无码av喷吹| 97香蕉久久夜色精品国产| 欧美精品久久久久久久自慰| 狠狠色丁香久久婷婷综合五月| 国产精品免费久久久久影院| 伊人久久精品影院| 狠狠色丁香婷综合久久| 亚洲一级Av无码毛片久久精品| 久久精品99久久香蕉国产色戒 | 性欧美大战久久久久久久久| 久久久久久狠狠丁香| 久久无码AV中文出轨人妻| 99久久99久久| 久久人妻少妇嫩草AV蜜桃| 亚洲一区二区三区日本久久九| 久久这里都是精品| 久久精品国产黑森林| …久久精品99久久香蕉国产| 国产精品久久久久久五月尺| 亚洲国产成人久久综合碰碰动漫3d | 久久久久久久免费视频| 国产精品久久久久久久午夜片| 日本久久久久亚洲中字幕 | 国内精品久久久久久久涩爱| 亚洲精品无码久久久影院相关影片 | 色综合久久88色综合天天| 无码人妻久久一区二区三区免费丨| 亚洲国产精品一区二区三区久久 | 久久青青草原精品影院| 亚洲国产欧洲综合997久久| 人人狠狠综合久久亚洲| 久久99久久成人免费播放| 久久青青草原精品影院| 7国产欧美日韩综合天堂中文久久久久| 99久久做夜夜爱天天做精品| 亚洲?V乱码久久精品蜜桃| 香蕉久久久久久狠狠色| 狠狠色丁香久久婷婷综合蜜芽五月| 亚洲国产成人久久综合区| 伊人久久五月天|