| Total Complexity | 16 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class CellsWithOddValueInAMatrix |
||
| 8 | { |
||
| 9 | public static function oddCells(int $m, int $n, array $indices): int |
||
| 10 | { |
||
| 11 | if ($m <= 0 || $n <= 0 || empty($indices)) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | |||
| 15 | [$cnt, $row, $col] = [0, array_fill(0, $m, 0), array_fill(0, $n, 0)]; |
||
| 16 | foreach ($indices as $item) { |
||
| 17 | $row[$item[0]]++; |
||
| 18 | $col[$item[1]]++; |
||
| 19 | } |
||
| 20 | for ($i = 0; $i < $m; $i++) { |
||
| 21 | for ($j = 0; $j < $n; $j++) { |
||
| 22 | if (($row[$i] + $col[$j]) % 2 !== 0) { |
||
| 23 | $cnt++; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | return $cnt; |
||
| 29 | } |
||
| 30 | |||
| 31 | public static function oddCells2(int $m, int $n, array $indices): int |
||
| 48 | } |
||
| 49 | } |
||
| 50 |