Test Failed
Push — master ( 1be827...0ae5c0 )
by Jinyun
02:12
created

Shift2DGrid   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A shiftGrid() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class Shift2DGrid
8
{
9
    public static function shiftGrid(array $grid, int $k): array
10
    {
11
        if (empty($grid)) {
12
            return [];
13
        }
14
        [$ans, $n] = [[], count($grid[0])];
15
        $arr = array_merge(...array_values($grid));
16
17
        while ($k--) {
18
            array_unshift($arr, array_pop($arr));
19
        }
20
        for ($i = 0, $m = count($arr); $i < $m; $i += $n) {
21
            array_push($ans, array_slice($arr, $i, $n));
22
        }
23
24
        return $ans;
25
    }
26
}
27