1217. 玩筹码

exiaohu 于 2022-07-08 发布

题目链接:1217. 玩筹码

移动筹码有一种方式:

这样移动,花费就是奇数位置和偶数位置上筹码的个数更少的那个。

from collections import Counter
from typing import List


class Solution:
    def minCostToMoveChips(self, position: List[int]) -> int:
        cnt = Counter(pos & 1 for pos in position)
        if len(cnt) <= 1:
            return 0

        return cnt.most_common(2)[1][1]