-
Notifications
You must be signed in to change notification settings - Fork 0
/
1252.php
33 lines (31 loc) · 842 Bytes
/
1252.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
class Solution
{
/**
* @param Integer $n
* @param Integer $m
* @param Integer[][] $indices
* @return Integer
*/
function oddCells($n, $m, $indices)
{
$row = [];
$col = [];
$odd_count = $m * $n;
foreach ($indices as $indice) {
if (isset($row[$indice[0]])) $row[$indice[0]] += 1;
else $row[$indice[0]] = 1;
if (isset($col[$indice[1]])) $col[$indice[1]] += 1;
else $col[$indice[1]] = 1;
}
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $m; $j++) {
$cnt = 0;
if (isset($row[$i])) $cnt += $row[$i];
if (isset($col[$j])) $cnt += $col[$j];
if ($cnt % 2 == 0) $odd_count--;
}
}
return $odd_count;
}
}