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

Shift2DGrid::shiftGrid()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
rs 9.9666
cc 4
nc 5
nop 2
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