Skip to content

Commit f532543

Browse files
add cpp solution #1288 (#91)
1 parent 6681a6c commit f532543

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

C++/Remove-Covered-Intervals.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//Problem Statement: Remove Covered Intervals
2+
3+
// Given a list of intervals, remove all intervals that are covered by another interval in the list.
4+
5+
// Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d.
6+
7+
// After doing so, return the number of remaining intervals.
8+
9+
//Solution:
10+
class Solution {
11+
public:
12+
int removeCoveredIntervals(vector<vector<int>>& intervals) {
13+
14+
int ans=0;
15+
for(int i=0; i<intervals.size(); i++) {
16+
for(int j=0; j<intervals.size(); j++) {
17+
if(i==j) continue;
18+
if(intervals[i][0] >= intervals[j][0] && intervals[i][1] <= intervals[j][1]) {
19+
// cout << i << endl;
20+
ans++; break;
21+
}
22+
}
23+
}
24+
25+
return intervals.size()-ans;
26+
}
27+
};
28+
29+
//Complexity: O(n*n)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
106106
| 532 | [K-diff Pairs in an Array](https://leetcode.com/problems/k-diff-pairs-in-an-array/) | [C++](./C++/k-diff-pairs-in-an-array.cpp) | O(n) | O(n) | Medium | Array |
107107
| 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/) | [Javascript](./JavaScript/152.Maximum-Product-Subarray.js) | O(n) | O(n) | Medium | Array |
108108
| 073 | [Set-Matrix-Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) | [Java](./Java/set-matrix-zeroes.java) | O(MN) | O(1) | Medium | Array |
109+
| 1288 | [Remove-Covered-Intervals](https://leetcode.com/problems/remove-covered-intervals) | [C++](./C++/Remove-Covered-Intervals.cpp) | O(N*N) | O(1) | Medium | Array |
109110

110111
<br/>
111112
<div align="right">

0 commit comments

Comments
 (0)