Leetcode Note: Go - Cells With Odd Values in a Matrix
Cells with Odd Values in a Matrix - LeetCode
https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/
- Go 言語で取り組んだメモ
回答
Cells with Odd Values in a Matrix - LeetCode
https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/solutions/1208519/golang-solution-faster-than-100-with-explanation-and-images/
func oddCells(n int, m int, indices [][]int) int {
x := make(map[int]int)
y := make(map[int]int)
counter := 0
for _, index := range indices {
y[index[0]]++
x[index[1]]++
}
for i := 0; i < n; i++ {
for j := 0; j < m; j++ {
if (y[i] + x[j]) % 2 == 1 {
counter++
}
}
}
return counter
}