• <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
            模擬一個支持不斷做snapshot并且可以查詢第i次snapshot時數組某個index的數值,數組中的所有數值都支持無限次set,并且由于memory限制,不能直接存儲每一次snapshot的數組所有元素
            參考了Discussion思路->https://leetcode.com/problems/snapshot-array/solutions/3623538/simple-java-c-python-easy-to-understand/


             1 #1146
             2 #Runtime: 706 ms (Beats 30.51%)
             3 #Memory: 45.6 MB (Beats 66.10%)
             4 
             5 class SnapshotArray(object):
             6 
             7     def __init__(self, length):
             8         """
             9         :type length: int
            10         """
            11         self.cur_arr = [0] * length
            12         self.his_arr = [[0] for _ in range(length)]
            13         self.modifed_idx_list = set()
            14         self.snap_id = 0
            15         self.snap_id_arr = [[-1] for _ in range(length)]
            16         
            17 
            18     def set(self, index, val):
            19         """
            20         :type index: int
            21         :type val: int
            22         :rtype: None
            23         """
            24         if self.his_arr[index][-1] == val:
            25             if index in self.modifed_idx_list:
            26                 self.modifed_idx_list.remove(index)
            27             return
            28         self.cur_arr[index] = val
            29         if index not in self.modifed_idx_list:
            30             self.modifed_idx_list.add(index)
            31         
            32 
            33     def snap(self):
            34         """
            35         :rtype: int
            36         """
            37         for i in self.modifed_idx_list:
            38             self.snap_id_arr[i].append(self.snap_id)
            39             self.his_arr[i].append(self.cur_arr[i])
            40         self.modifed_idx_list.clear()
            41         self.snap_id += 1
            42         return self.snap_id - 1
            43 
            44 
            45     def get(self, index, snap_id):
            46         """
            47         :type index: int
            48         :type snap_id: int
            49         :rtype: int
            50         """
            51         arr = self.snap_id_arr[index]
            52         l, r = 1, len(arr)
            53         while l < r:
            54             mid = (l + r) // 2
            55             if arr[mid] <= snap_id:
            56                 l = mid + 1
            57             else:
            58                 r = mid
            59         return self.his_arr[index][l - 1]
            60         
            61 
            62 
            63 # Your SnapshotArray object will be instantiated and called as such:
            64 # obj = SnapshotArray(length)
            65 # obj.set(index,val)
            66 # param_2 = obj.snap()
            67 # param_3 = obj.get(index,snap_id)
            武侠古典久久婷婷狼人伊人| 国内精品久久人妻互换| 久久国产影院| 热久久最新网站获取| 久久国产免费观看精品3| 精品999久久久久久中文字幕| 国产精品美女久久久网AV| 国产亚洲美女精品久久久2020| 久久精品国产亚洲综合色| 热99RE久久精品这里都是精品免费 | 久久久久亚洲av成人无码电影| 色婷婷噜噜久久国产精品12p | 久久精品国产91久久麻豆自制 | 精品国产日韩久久亚洲| 99久久精品免费| 777米奇久久最新地址| 精品久久久久久久国产潘金莲 | 久久久久久夜精品精品免费啦| 香港aa三级久久三级老师2021国产三级精品三级在 | 亚洲国产一成久久精品国产成人综合| 99精品国产综合久久久久五月天| 久久精品人妻一区二区三区| 久久青青草原亚洲av无码app| 久久毛片一区二区| 亚洲人成无码网站久久99热国产 | 91麻精品国产91久久久久 | 欧美精品一区二区久久| 国产成人精品久久亚洲| 日韩精品久久久久久| 国产V亚洲V天堂无码久久久| 久久亚洲欧美国产精品| 久久久久无码精品国产| 欧美va久久久噜噜噜久久| 色综合久久中文字幕无码| 久久久无码精品亚洲日韩蜜臀浪潮| 久久久久人妻精品一区三寸蜜桃| 国产精品美女久久久免费| 久久久WWW成人免费毛片| 一本大道久久东京热无码AV| 亚洲第一永久AV网站久久精品男人的天堂AV | 99久久成人国产精品免费|