Leetcode Note: Go - Minimum Cost to Move Chips to the Same Position
Minimum Cost to Move Chips to The Same Position - LeetCode
https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position/
- Go 言語で取り組んだメモ
回答
Minimum Cost to Move Chips to The Same Position - LeetCode
https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position/solutions/1194574/two-golang-solutions-both-faster-than-100-with-explanation/
func minCostToMoveChips(position []int) int {
odd, even := 0, 0
for _, currentPosition := range position {
if currentPosition % 2 == 0 {
odd++
} else {
even++
}
}
if even < odd {
return even
}
return odd
}