We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 460af9d commit 347ebe4Copy full SHA for 347ebe4
src/0057-Insert-Interval/0057.cpp
@@ -0,0 +1,27 @@
1
+#include <vector>
2
+using namespace std;
3
+
4
+static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
5
+class Solution
6
+{
7
+public:
8
+ vector<Interval> insert(vector<Interval>& intervals, Interval newInterval)
9
+ {
10
+ vector<Interval> res;
11
+ int i = 0;
12
+ while (i < intervals.size() and intervals[i].end < newInterval.start)
13
14
+ res.push_back(intervals[i++]);
15
+ }
16
17
+ while (i < intervals.size() and intervals[i].start <= newInterval.end)
18
19
+ newInterval.start = min(intervals[i].start, newInterval.start);
20
+ newInterval.end = max(intervals[i].end, newInterval.end);
21
+ ++i;
22
23
+ res.push_back(newInterval);
24
+ for (; i < intervals.size(); ++i) res.push_back(intervals[i]);
25
+ return res;
26
27
+};
src/0057-Insert-Interval/0057.py
0 commit comments