Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1d6010d

Browse files
solved algorithm daily challege, minimum range cover
1 parent e760c44 commit 1d6010d

File tree

1 file changed

+80
-0
lines changed
  • LintCode/1668_Minimum_Range_Cover

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <bits/stdc++.h>
2+
#include <gtest/gtest.h>
3+
using namespace std;
4+
5+
6+
//// START
7+
/*
8+
## 1668 Minimum Range Cover
9+
10+
*/
11+
12+
/**
13+
* Definition of Interval:
14+
* classs Interval {
15+
* int start, end;
16+
* Interval(int start, int end) {
17+
* this->start = start;
18+
* this->end = end;
19+
* }
20+
* }
21+
*/
22+
bool cpr(const Interval &i1,const Interval &i2){
23+
if (i1.start == i2.start) return i1.end < i2.end;
24+
return i1.start < i2.start;
25+
}
26+
27+
class Solution {
28+
public:
29+
/**
30+
* @param a: the array a
31+
* @return: return the minimal points number
32+
*/
33+
int getAns(vector<Interval> &a) {
34+
int count = 0;
35+
sort(a.begin(),a.end(),cpr);
36+
for (int i = 0;i < a.size();i++){
37+
auto end = a[i].end;
38+
39+
while(i < a.size() && a[i].start <= end ){
40+
end = min(a[i].end,end);
41+
i++;
42+
}
43+
i--;
44+
count++;
45+
}
46+
return count;
47+
}
48+
};
49+
50+
51+
//// END
52+
struct T{
53+
54+
};
55+
56+
TEST(Solution,test){
57+
T ts[] = {
58+
{
59+
60+
},
61+
{
62+
63+
},
64+
65+
};
66+
67+
68+
for (T t : ts){
69+
Solution solution;
70+
71+
}
72+
}
73+
74+
int main() {
75+
testing::InitGoogleTest();
76+
77+
return RUN_ALL_TESTS();
78+
}
79+
80+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /