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

RotateImage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A rotate() 0 13 4
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