-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1288.php
33 lines (32 loc) · 826 Bytes
/
1288.php
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
<?php
class Solution
{
/**
* @param Integer[][] $intervals
* @return Integer
*/
public function removeCoveredIntervals($intervals)
{
// sort($intervals);
usort($intervals, function ($a, $b) {
if ($a[0] == $b[0]) {
return $b[1] - $a[1];
}
return $a[0] - $b[0];
});
$start = $intervals[0][0];
$end = $intervals[0][1];
$total = count($intervals);
array_shift($intervals);
$count = 0;
foreach ($intervals as $interval) {
if ($start <= $interval[0] && $interval[1] <= $end) {
$count++;
} else {
$start = $interval[0];
$end = $interval[1];
}
}
return $total - $count;
}
}