Issues (64)

src/leetcode/MinimumFallingPathSumII.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class MinimumFallingPathSumII
8
{
9
    public static function minFallingPathSum(array $grid): int
10
    {
11
        if (empty($grid)) {
12
            return 0;
13
        }
14
        [$m, $n] = [count($grid), count($grid[0])];
15
        $curr = $grid[0];
16
        for ($i = 1; $i < $m; $i++) {
17
            $next = $data = [];
18
            self::helper($curr, $data);
19
            $vals = array_slice($data, 0, 2);
20
            for ($j = 0; $j < $n; $j++) {
21
                $temp = $vals[0][1] === $j ? $vals[1][0] : $vals[0][0];
22
                array_push($next, $grid[$i][$j] + $temp);
23
            }
24
            $curr = $next;
25
        }
26
27
        return min($curr);
28
    }
29
30
    private static function helper(array $item, array &$data): void
31
    {
32
        foreach ($item as $key => $val) {
33
            $data[] = [$val, $key];
34
        }
35
36
        array_multisort($data, SORT_ASC);
0 ignored issues
show
leetcode\SORT_ASC cannot be passed to array_multisort() as the parameter $rest expects a reference. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        array_multisort($data, /** @scrutinizer ignore-type */ SORT_ASC);
Loading history...
37
    }
38
}
39