• <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
            構建一個data stream,有以下三種操作:

            SummaryRanges() -> Initializes the object with an empty stream.
            void addNum(int value) -> Adds the integer value to the stream.
            int[][] getIntervals() -> Returns a summary of the integers in the stream currently as a list of disjoint intervals [starti, endi]. The answer should be sorted by starti.

            Discussion中有人使用python的Sorted List,其實不必,參考->https://leetcode.com/problems/data-stream-as-disjoint-intervals/solutions/531106/python-solution-using-bisect-to-do-binary-search-beating-99-5-in-time/

            初始化兩個intervals:[[-10001, -10001], [10001, 10001]] (比data stream小1或者大1即可),每次插入時調用bisect.bisect返回該插入在何處,通過判斷當前要插入的值是否與前一個或者后一個區間有overlap來決定是否需要合并區間


             1 #352
             2 #Runtime: 115 ms (Beats 100%)
             3 #Memory: 18.5 MB (Beats 88.46%)
             4 
             5 class SummaryRanges(object):
             6 
             7     def __init__(self):
             8         self.ds = [[-10001, -10001], [10001, 10001]]
             9 
            10     def addNum(self, value):
            11         """
            12         :type value: int
            13         :rtype: None
            14         """
            15         idx = bisect.bisect(self.ds, [value])
            16         l1, l2 = self.ds[idx - 1]
            17         r1, r2 = self.ds[idx]
            18         if l2 == value - 1 and r1 == value + 1:
            19             self.ds = self.ds[ : idx - 1] + [[l1, r2]] + self.ds[idx + 1 : ]
            20         elif l2 == value - 1:
            21             self.ds[idx - 1][1] = value
            22         elif r1 == value + 1:
            23             self.ds[idx][0] = value
            24         elif l2 < value - 1 and r1 > value + 1:
            25             self.ds = self.ds[ : idx] + [[value, value]] + self.ds[idx : ]
            26         
            27 
            28     def getIntervals(self):
            29         """
            30         :rtype: List[List[int]]
            31         """
            32         return self.ds[1 : -1]
            33         
            34 
            35 
            36 # Your SummaryRanges object will be instantiated and called as such:
            37 # obj = SummaryRanges()
            38 # obj.addNum(value)
            39 # param_2 = obj.getIntervals()
            久久亚洲AV无码精品色午夜 | 日韩久久久久久中文人妻 | 国产精品一久久香蕉产线看| 777米奇久久最新地址| 青青草原综合久久| 亚洲第一永久AV网站久久精品男人的天堂AV| 久久久久婷婷| 国内精品九九久久久精品| 日本精品久久久久中文字幕8| 久久91这里精品国产2020| 无码国产69精品久久久久网站| 99久久国产综合精品网成人影院| 伊人久久大香线蕉无码麻豆| 久久99热精品| 久久精品国产亚洲av麻豆小说| 久久久久亚洲精品天堂久久久久久 | 青草国产精品久久久久久| 香港aa三级久久三级| 久久久久久久波多野结衣高潮| 成人午夜精品久久久久久久小说| 久久99九九国产免费看小说| 亚洲综合精品香蕉久久网97| 欧美va久久久噜噜噜久久| 久久综合亚洲色一区二区三区| 蜜桃麻豆www久久| 国产精品美女久久久久久2018| 欧美黑人激情性久久| 亚洲精品成人久久久| 久久影视综合亚洲| 国产综合精品久久亚洲| 国产午夜精品理论片久久影视 | 久久成人国产精品一区二区| 99久久久精品免费观看国产| 日日躁夜夜躁狠狠久久AV| 国产aⅴ激情无码久久| 一级做a爰片久久毛片免费陪 | 久久天堂AV综合合色蜜桃网| 99蜜桃臀久久久欧美精品网站| 久久无码中文字幕东京热| 伊人热热久久原色播放www| 欧美成人免费观看久久|