| Conditions | 4 |
| Paths | 6 |
| Total Lines | 12 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | } |
||
| 23 |