• <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()
            久久这里的只有是精品23| 麻豆久久久9性大片| 色婷婷噜噜久久国产精品12p | 亚洲国产成人久久笫一页| 精品久久人人妻人人做精品| 日本久久久精品中文字幕| 久久久久久国产精品无码超碰| 免费久久人人爽人人爽av| 7777精品久久久大香线蕉| 亚洲级αV无码毛片久久精品 | 99久久精品费精品国产 | 国内精品久久久久久久亚洲| 久久久久99精品成人片欧美| 久久午夜夜伦鲁鲁片免费无码影视| 大香伊人久久精品一区二区| 2021国内精品久久久久久影院| 欧美亚洲国产精品久久久久| 久久精品无码一区二区三区免费| 午夜不卡久久精品无码免费| 国产精品99久久久精品无码| 精品多毛少妇人妻AV免费久久| 久久婷婷五月综合97色| A级毛片无码久久精品免费| 一本综合久久国产二区| 亚洲综合伊人久久综合| 国产成年无码久久久久毛片| 久久久青草青青国产亚洲免观| 欧美噜噜久久久XXX| 久久91亚洲人成电影网站| 亚洲婷婷国产精品电影人久久| 久久久精品国产免大香伊| 久久精品国内一区二区三区| 久久亚洲高清综合| 7777久久亚洲中文字幕| 欧美色综合久久久久久| 亚洲AV无码久久精品成人| 久久青青草原精品影院| 亚洲国产另类久久久精品| 久久久艹| 国产亚洲欧美成人久久片| 色青青草原桃花久久综合|