• <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
            模擬一個(gè)支持不斷做snapshot并且可以查詢第i次snapshot時(shí)數(shù)組某個(gè)index的數(shù)值,數(shù)組中的所有數(shù)值都支持無限次set,并且由于memory限制,不能直接存儲(chǔ)每一次snapshot的數(shù)組所有元素
            參考了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)
            亚洲伊人久久精品影院| 久久久99精品一区二区| 亚洲а∨天堂久久精品| 91精品婷婷国产综合久久| 久久99国产精品二区不卡| 无码人妻精品一区二区三区久久| 欧美久久亚洲精品| 免费一级欧美大片久久网| 久久精品国产精品亚洲| 狠狠色伊人久久精品综合网| 中文字幕亚洲综合久久2| 国产精品丝袜久久久久久不卡| 久久综合中文字幕| 欧美久久亚洲精品| 久久免费看黄a级毛片| 久久久久久久久无码精品亚洲日韩| 无码人妻精品一区二区三区久久| 久久99精品国产自在现线小黄鸭| 久久天天躁狠狠躁夜夜avapp | 久久久久亚洲av无码专区| 熟妇人妻久久中文字幕| 久久国产精品久久久| 久久久久国产一级毛片高清板| 久久国产视屏| 久久久久亚洲AV无码专区体验| 亚洲欧美精品伊人久久| 色诱久久av| 国内精品久久九九国产精品| 久久久受www免费人成| 精品久久久无码人妻中文字幕| 2022年国产精品久久久久| 久久成人精品| 国产精品美女久久久m| 久久人人超碰精品CAOPOREN| 久久婷婷五月综合97色一本一本| 久久国产香蕉一区精品| 99久久精品国产高清一区二区| 久久久WWW成人免费精品| 久久精品无码午夜福利理论片| 久久精品国产99久久久香蕉| 久久久久亚洲Av无码专|