Skip to content

Commit

Permalink
Create 1288.Remove-Covered-Intervals_v1.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Dec 25, 2020
1 parent b1a2b7d commit 08f3e21
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution {
static bool cmp(pair<int,int>&a, pair<int,int>&b)
{
if (a.first!=b.first)
return a.first < b.first;
else
return a.second > b.second;
}
public:
int removeCoveredIntervals(vector<vector<int>>& intervals)
{
vector<pair<int,int>>p;
for (auto& interval: intervals)
{
p.push_back({interval[0],1});
p.push_back({interval[1],-1});
}
sort(p.begin(), p.end(), cmp);
int diff = 0;
int ret = 0;
for (auto x: p)
{
diff += x.second;
if (x.second==-1 && diff == 0)
ret++;
}
return ret;
}
};

0 comments on commit 08f3e21

Please sign in to comment.