1217. Minimum Cost to Move Chips to The Same Position
Python
題目難懂而已,移動2步cost為零,問的只是奇數多還是偶數多
class Solution:
def minCostToMoveChips(self, position: List[int]) -> int:
if not position:
return 0
odd_count = len([i for i in position if i % 2 == 1])
even_count = len([i for i in position if i % 2 == 0])
if odd_count > even_count:
return even_count
return odd_count