Conditions | 8 |
Paths | 7 |
Total Lines | 19 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | public static function distanceBetweenBusStops(array $distance, int $start, int $destination): int |
||
10 | { |
||
11 | if (empty($distance) || $start < 0 || $destination < 0) { |
||
12 | return 0; |
||
13 | } |
||
14 | if ($start > $destination) { |
||
15 | $tmp = $start; |
||
16 | $start = $destination; |
||
17 | $destination = $tmp; |
||
18 | } |
||
19 | $res = $sum = 0; |
||
20 | foreach ($distance as $i => $value) { |
||
21 | if ($i >= $start && $i < $destination) { |
||
22 | $res += $value; |
||
23 | } |
||
24 | $sum += $value; |
||
25 | } |
||
26 | |||
27 | return min($res, $sum - $res); |
||
28 | } |
||
41 |