File tree 2 files changed +24
-0
lines changed
September-LeetCoding-Challenge/13-Insert-Interval 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ Solutions in various programming languages are provided. Enjoy it.
19
19
10 . [ Bulls and Cows] ( https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/10-Bulls-and-Cows )
20
20
11 . [ Maximum Product Subarray] ( https://github.com/AlgoStudyGroup/Leetcode/tree/master/September-LeetCoding-Challenge/11-Maximum-Product-Subarray )
21
21
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 )
22
23
23
24
## August LeetCoding Challenge
24
25
Click [ here] ( https://leetcode.com/explore/challenge/card/august-leetcoding-challenge/ ) for problem descriptions.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments