ReshapeTheMatrix   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A matrixReshape() 0 12 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class ReshapeTheMatrix
8
{
9
    public static function matrixReshape(array $nums, int $r, int $c): array
10
    {
11
        [$n, $m] = [count($nums), empty($nums[0]) ? 0 : count($nums[0])];
12
        if ($n * $m !== $r * $c) {
13
            return $nums;
14
        }
15
        $ans = [];
16
        for ($i = 0; $i < $r * $c; $i++) {
17
            $ans[$i / $c][$i % $c] = $nums[$i / $m][$i % $m];
18
        }
19
20
        return $ans;
21
    }
22
}
23