mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-08-03 02:47:26 +08:00
24 lines
495 B
Go
24 lines
495 B
Go
package leetcode
|
|
|
|
func numEquivDominoPairs(dominoes [][]int) int {
|
|
if dominoes == nil || len(dominoes) == 0 {
|
|
return 0
|
|
}
|
|
result, buckets := 0, [100]int{}
|
|
for _, dominoe := range dominoes {
|
|
key, rotatedKey := dominoe[0]*10+dominoe[1], dominoe[1]*10+dominoe[0]
|
|
if dominoe[0] != dominoe[1] {
|
|
if buckets[rotatedKey] > 0 {
|
|
result += buckets[rotatedKey]
|
|
}
|
|
}
|
|
if buckets[key] > 0 {
|
|
result += buckets[key]
|
|
buckets[key]++
|
|
} else {
|
|
buckets[key]++
|
|
}
|
|
}
|
|
return result
|
|
}
|