FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Leetcode/0057_Insert_Interval.cpp at main · Nothing-avil/Leetcode · GitHub
Nothing-avil
/
Leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
4
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Leetcode
/
0057_Insert_Interval.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (30 loc) · 1007 Bytes
Breadcrumbs
Leetcode
/
0057_Insert_Interval.cpp
Copy path
File metadata and controls
30 lines (30 loc) · 1007 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#
pragma
GCC optimize("Ofast","inline","ffast-math","unroll-loops","no-stack-protector")
#
pragma
GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native","f16c")
class
Solution
{
public:
vector<vector<
int
>>
insert
(vector<vector<
int
>>& intervals, vector<
int
>& newInterval) {
ios_base::sync_with_stdio
(
0
), cin.
tie
(
0
), cout.
tie
(
0
);
vector<vector<
int
>> res;
int
i=
0
;
int
n= intervals.
size
();
while
(i<n){
if
(intervals[i][
1
]<newInterval[
0
]){
res.
push_back
(intervals[i]);
}
else
if
(intervals[i][
0
]>newInterval[
1
]){
break
;
}
else
{
newInterval[
0
]=
min
(newInterval[
0
], intervals[i][
0
]);
newInterval[
1
]=
max
(newInterval[
1
], intervals[i][
1
]);
}
i++;
}
res.
push_back
(newInterval);
while
(i<n){
res.
push_back
(intervals[i]);
i++;
}
return
res;
}
};
Back
|
FazBrowse Home
|
New Git URL