-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
33 lines (33 loc) · 843 Bytes
/
Solution.cs
File metadata and controls
33 lines (33 loc) · 843 Bytes
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
public class Solution
{
public int IntersectionSizeTwo(int[][] intervals)
{
Array.Sort(intervals, (a, b) =>
{
if (a[0] == b[0]) return b[1] - a[1];
return a[0] - b[0];
});
int n = intervals.Length;
int[] todo = new int[n];
Array.Fill(todo, 2);
int ans = 0, t = n;
while (--t >= 0)
{
int s = intervals[t][0];
int e = intervals[t][1];
int m = todo[t];
for (int p = s; p < s + m; p++)
{
for (int i = 0; i <= t; i++)
{
if (todo[i] > 0 && p <= intervals[i][1])
{
todo[i]--;
}
}
ans++;
}
}
return ans;
}
}