ToeplitzMatrix::isToeplitzMatrix()   B
last analyzed

Complexity

Conditions 7
Paths 10

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 15
rs 8.8333
cc 7
nc 10
nop 1
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