Leetcode Note: Go - Maximum Number of Pairs in Array
Maximum Number of Pairs in Array - LeetCode
https://leetcode.com/problems/maximum-number-of-pairs-in-array/
- Go 言語で取り組んだメモ
回答
Maximum Number of Pairs in Array - LeetCode
https://leetcode.com/problems/maximum-number-of-pairs-in-array/solutions/3639796/go-and-rust-solution/
func numberOfPairs(nums []int) []int {
out := make([]int, 2)
hashmap := make(map[int]int)
for _, num := range nums {
hashmap[num] += 1
}
for _, v := range hashmap {
out[0] += v / 2
out[1] += v % 2
}
return out
}