Conditions | 8 |
Paths | 9 |
Total Lines | 17 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
31 | public static function oddCells2(int $m, int $n, array $indices): int |
||
32 | { |
||
33 | if ($m <= 0 || $n <= 0 || empty($indices)) { |
||
34 | return 0; |
||
35 | } |
||
36 | [$cnt, $row, $col] = [0, array_fill(0, $m, false), array_fill(0, $n, false)]; |
||
37 | foreach ($indices as $item) { |
||
38 | $row[$item[0]] ^= true; |
||
39 | $col[$item[1]] ^= true; |
||
40 | } |
||
41 | for ($i = 0; $i < $m; $i++) { |
||
42 | for ($j = 0; $j < $n; $j++) { |
||
43 | $cnt += $row[$i] ^ $col[$j] ? 1 : 0; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | return $cnt; |
||
48 | } |
||
50 |