ToeplitzMatrix   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 9
c 2
b 0
f 0
dl 0
loc 17
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B isToeplitzMatrix() 0 15 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace leetcode;
6
7
class ToeplitzMatrix
8
{
9
    public static function isToeplitzMatrix(array $matrix): bool
10
    {
11
        [$m, $n] = [count($matrix), empty($matrix[0]) ? 0 : count($matrix[0])];
12
        if ($m <= 0 || $n <= 0) {
13
            return false;
14
        }
15
        for ($i = 0; $i < $m - 1; $i++) {
16
            for ($j = 0; $j < $n - 1; $j++) {
17
                if ($matrix[$i][$j] !== $matrix[$i + 1][$j + 1]) {
18
                    return false;
19
                }
20
            }
21
        }
22
23
        return true;
24
    }
25
}
26