Test Failed
Push — master ( 0ae5c0...a6ce87 )
by Jinyun
15:18
created

minTimeToVisitAllPoints()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class MinimumTimeVisitingAllPoints
8
{
9
    public static function minTimeToVisitAllPoints(array $points): int
10
    {
11
        if (empty($points)) {
12
            return 0;
13
        }
14
        [$ans, $n] = [0, count($points)];
15
        for ($i = 1; $i < $n; $i++) {
16
            [$prev, $curr] = [$points[$i - 1], $points[$i]];
17
            $ans += max(abs($curr[0] - $prev[0]), abs($curr[1] - $prev[1]));
18
        }
19
20
        return $ans;
21
    }
22
}
23