Skip to content

Commit d120d19

Browse files
committed
Runtime: 48 ms (41.99%), Memory: 16.5 MB (73.19%) - Gitcode
1 parent 29a6281 commit d120d19

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:
3+
# Initialize row and column counters
4+
row_count = [0] * m
5+
col_count = [0] * n
6+
7+
# Increment the row and column counters based on the indices
8+
for r, c in indices:
9+
row_count[r] += 1
10+
col_count[c] += 1
11+
12+
# Count the number of cells with odd values
13+
odd_count = 0
14+
for i in range(m):
15+
for j in range(n):
16+
# The value at cell (i, j) is odd if the sum of row_count[i] and col_count[j] is odd
17+
if (row_count[i] + col_count[j]) % 2 != 0:
18+
odd_count += 1
19+
20+
return odd_count
21+
22+

0 commit comments

Comments
 (0)