Content-Length: 318415 | pFad | http://github.com/AlgoStudyGroup/Leetcode/commit/1a40ddb98983c7f7ca113c2718db12a76653beaf

3F Merge pull request #284 from hellomrsun/master · AlgoStudyGroup/Leetcode@1a40ddb · GitHub
Skip to content

Commit 1a40ddb

Browse files
authored
Merge pull request #284 from hellomrsun/master
Add Insert Interval
2 parents 92cde71 + 048e60c commit 1a40ddb

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Solutions in various programming languages are provided. Enjoy it.
1919
10. [Bulls and Cows](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/10-Bulls-and-Cows)
2020
11. [Maximum Product Subarray](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/11-Maximum-Product-Subarray)
2121
12. [Combination Sum III](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/12-Combination-Sum-III)
22+
13. [Insert Interval](https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/13-Insert-Interval)
2223

2324
## August LeetCoding Challenge
2425
Click [here](https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/) for problem descriptions.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class Solution {
2+
public int[][] Insert(int[][] intervals, int[] newInterval) {
3+
var res = new List<int[]>();
4+
foreach(int[] i in intervals){
5+
if(newInterval == null || i[1] < newInterval[0]){
6+
res.Add(i);
7+
}
8+
else if(i[0] > newInterval[1]){
9+
res.Add(newInterval);
10+
res.Add(i);
11+
newInterval = null;
12+
}
13+
else{
14+
newInterval[0] = Math.Min(newInterval[0], i[0]);
15+
newInterval[1] = Math.Max(newInterval[1], i[1]);
16+
}
17+
}
18+
if(newInterval != null){
19+
res.Add(newInterval);
20+
}
21+
return res.ToArray();
22+
}
23+
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/AlgoStudyGroup/Leetcode/commit/1a40ddb98983c7f7ca113c2718db12a76653beaf

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy