leetcode:Data Stream as Disjoint Intervals(352)

原创 2016年08月31日 14:56:04

https://leetcode.com/problems/data-stream-as-disjoint-intervals/


class SummaryRanges {  
public:  
    /** Initialize your data structure here. */  
    void addNum(int val) {  
        auto it = st.lower_bound(Interval(val, val));  
        int start = val, end = val;  
        if(it != st.begin() && (--it)->end+1 < val) it++;  
        while(it != st.end() && val+1 >= it->start && val-1 <= it->end)  
        {  
            start = min(start, it->start);  
            end = max(end, it->end);  
            it = st.erase(it);  
        }  
        st.insert(it,Interval(start, end));  
    }  

    vector<Interval> getIntervals() {  
        vector<Interval> result;  
        for(auto val: st) result.push_back(val);  
        return result;  
    }  
private:  
    struct Cmp{  
        bool operator()(Interval a, Interval b) { return a.start < b.start; }  
    };  
    set<Interval, Cmp> st;  
};  
版权声明:本文为博主原创文章,未经博主允许不得转载。

LeetCode 352. Data Stream as Disjoint Intervals(数据流区间)

原题网址:https://leetcode.com/problems/data-stream-as-disjoint-intervals/ Given a data stream input...
  • jmspan
  • jmspan
  • 2016年06月16日 01:11
  • 939

[leetcode] 352. Data Stream as Disjoint Intervals 解题报告

题目链接: https://leetcode.com/problems/data-stream-as-disjoint-intervals/ Given a data stream input o...

352. Data Stream as Disjoint Intervals

352. Data Stream as Disjoint Intervals

leetcode 295. Find Median from Data Stream

Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...

LeetCode 295. Find Median from Data Stream(数据流中位数)

原题网址:https://leetcode.com/problems/find-median-from-data-stream/ Median is the middle value in an ...
  • jmspan
  • jmspan
  • 2016年04月16日 11:09
  • 414

Leetcode (295) Find Median from Data Stream

Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...

Find Median from Data Stream -- Leetcode

Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...

LeetCode295:Find Median from Data Stream

最大最小堆 时间复杂度 O(NlogN) 空间O(N) 维护一个最大堆,一个最小堆,最大堆存的是到目前为止较小的那一半数,最小堆是到目前为止较大的那一半数 最大堆是目前为止较小的那一半数最好在脑子...

[Leetcode] 295. Find Median from Data Stream 解题报告

题目: Median is the middle value in an ordered integer list. If the size of the list is even, the...

《leetcode》:Find Median from Data Stream

题目Median is the middle value in an ordered integer list. If the size of the list is even, there is n...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:leetcode:Data Stream as Disjoint Intervals(352)
举报原因:
原因补充:

(最多只允许输入30个字)