• <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òu)建一個(gè)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,其實(shí)不必,參考->https://leetcode.com/problems/data-stream-as-disjoint-intervals/solutions/531106/python-solution-using-bisect-to-do-binary-search-beating-99-5-in-time/

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


             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()
            草草久久久无码国产专区| 久久精品亚洲中文字幕无码麻豆| 久久综合狠狠综合久久综合88| 亚洲中文精品久久久久久不卡| 亚洲国产精品无码成人片久久| 久久天堂AV综合合色蜜桃网| 精品久久久一二三区| 91精品国产综合久久精品| 国产99精品久久| 久久精品成人免费看| 亚洲伊人久久综合中文成人网| 性做久久久久久久| 久久久久免费看成人影片| 精品无码久久久久国产| 午夜精品久久久久久久无码| 午夜精品久久久久久99热| 久久久久久久97| 欧美综合天天夜夜久久| 99久久精品免费看国产一区二区三区 | 久久久无码精品亚洲日韩京东传媒| 狠狠色丁香久久婷婷综合五月| 国内精品久久久久影院日本| 国产99久久久国产精免费| 亚洲午夜精品久久久久久浪潮| 久久天天躁狠狠躁夜夜2020一| 久久婷婷五月综合色高清| 久久婷婷国产麻豆91天堂| 久久久久人妻一区精品| 日本精品久久久久中文字幕| 久久久久国产一区二区| 亚洲精品tv久久久久久久久| 久久福利青草精品资源站| 欧美日韩精品久久久免费观看| 色偷偷偷久久伊人大杳蕉| 精品久久久久久久中文字幕| 欧美激情精品久久久久| 亚洲精品乱码久久久久久蜜桃| 国产美女久久精品香蕉69| 手机看片久久高清国产日韩| 韩国无遮挡三级久久| 思思久久精品在热线热|