Test Failed
Push — master ( e3b2de...5cce80 )
by Jinyun
09:41
created

RotateImage::rotate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 13
rs 9.9332
cc 4
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class RotateImage
8
{
9
    public static function rotate(array &$matrix): void
10
    {
11
        $n = count($matrix);
12
        if ($n <= 1) {
13
            return;
14
        }
15
        for ($i = 0; $i < intdiv($n, 2); $i++) { // col
16
            for ($j = $n - $i - 1; $j > $i; $j--) { // row
17
                $t = $matrix[$j][$i];
18
                $matrix[$j][$i] = $matrix[$n - $i - 1][$j];
19
                $matrix[$n - $i - 1][$j] = $matrix[$n - $j - 1][$n - $i - 1];
20
                $matrix[$n - $j - 1][$n - $i - 1] = $matrix[$i][$n - $j - 1];
21
                $matrix[$i][$n - $j - 1] = $t;
22
            }
23
        }
24
    }
25
}
26