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

MinimumTimeVisitingAllPoints   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 14
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A minTimeToVisitAllPoints() 0 12 3
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