Skip to content

Commit 0ea2c94

Browse files
committed
Runtime: 56 ms (Top 88.46%) | Memory: 17.8 MB (Top 31.41%)
1 parent fa0e184 commit 0ea2c94

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1+
// Runtime: 56 ms (Top 88.46%) | Memory: 17.8 MB (Top 31.41%)
12
class Solution {
23
public:
3-
4+
45
// sort wrt. end value
5-
6+
67
static bool compare(vector<int>& a, vector<int>& b)
78
{
89
if(a[1] == b[1])
910
return a[0] < b[0];
1011
else
1112
return a[1] < b[1];
1213
}
13-
14+
1415
int intersectionSizeTwo(vector<vector<int>>& intervals) {
15-
16+
1617
int n = intervals.size();
17-
18+
1819
// sort the array
19-
20+
2021
sort(intervals.begin(), intervals.end(), compare);
21-
22+
2223
vector<int> res;
23-
24+
2425
res.push_back(intervals[0][1] - 1);
25-
26+
2627
res.push_back(intervals[0][1]);
27-
28+
2829
for(int i = 1; i < n; i++)
2930
{
3031
int start = intervals[i][0];
31-
32+
3233
int end = intervals[i][1];
33-
34+
3435
if(start > res.back())
3536
{
3637
res.push_back(end - 1);
37-
38+
3839
res.push_back(end);
3940
}
4041
else if(start == res.back())
@@ -46,7 +47,7 @@ class Solution {
4647
res.push_back(end);
4748
}
4849
}
49-
50+
5051
return res.size();
5152
}
52-
};
53+
};

0 commit comments

Comments
 (0)