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 1026f68

Browse files
Merge pull request #15 from SaranshBangar/17/03/2024
Added LeetCode POTD (17/03/2024) solution in C++
2 parents a84b648 + 5c035e1 commit 1026f68

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎2024/03 - March/17-03-2024.cpp‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
3+
Author : Saransh Bangar
4+
Date : 17/03/2024
5+
Problem : Insert Interval
6+
Difficulty : Medium
7+
Problem Link : https://leetcode.com/problems/insert-interval/description/
8+
Video Solution : NA
9+
10+
*/
11+
12+
13+
class Solution {
14+
public:
15+
vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval)
16+
{
17+
vector<vector<int>>ans;
18+
int i=0;
19+
while (i<intervals.size() && intervals[i][1]<newInterval[0])
20+
{
21+
ans.push_back(intervals[i]);
22+
i++;
23+
}
24+
while (i<intervals.size() && intervals[i][0]<=newInterval[1])
25+
{
26+
newInterval[0]=min(newInterval[0], intervals[i][0]);
27+
newInterval[1]=max(newInterval[1], intervals[i][1]);
28+
i++;
29+
}
30+
ans.push_back(newInterval);
31+
while (i<intervals.size())
32+
{
33+
ans.push_back(intervals[i]);
34+
i++;
35+
}
36+
return ans;
37+
}
38+
};

0 commit comments

Comments
(0)

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