-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution986.cs
40 lines (34 loc) · 995 Bytes
/
Solution986.cs
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
31
32
33
34
35
36
37
38
39
40
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution986
{
/// <summary>
/// 986. Interval List Intersections - Medium
/// <a href="https://leetcode.com/problems/interval-list-intersections">See the problem</a>
/// </summary>
public int[][] IntervalIntersection(int[][] firstList, int[][] secondList)
{
var result = new List<int[]>();
var i = 0;
var j = 0;
while (i < firstList.Length && j < secondList.Length)
{
var start = Math.Max(firstList[i][0], secondList[j][0]);
var end = Math.Min(firstList[i][1], secondList[j][1]);
if (start <= end)
{
result.Add(new int[] { start, end });
}
if (firstList[i][1] < secondList[j][1])
{
i++;
}
else
{
j++;
}
}
return [.. result];
}
}