zoukankan      html  css  js  c++  java
  • 1217. Play with Chips

    There are some chips, and the i-th chip is at position chips[i].

    You can perform any of the two following types of moves any number of times (possibly zero) on any chip:

    • Move the i-th chip by 2 units to the left or to the right with a cost of 0.
    • Move the i-th chip by 1 unit to the left or to the right with a cost of 1.

    There can be two or more chips at the same position initially.

    Return the minimum cost needed to move all the chips to the same position (any position).

    移动一格cost1,移动2格cost0,本质上偶数位置的可以免费移动到任意偶数位,奇数位可以免费移动到任意奇数位,那实际上就可以把奇的都放到一个位置上,偶的放到一个位置上,然后哪边少就把少的移动到多的去。

    class Solution(object):
        def minCostToMoveChips(self, chips):
            """
            :type chips: List[int]
            :rtype: int
            """
            odd = 0
            even = 0
            for chip in chips:
                if chip % 2 == 0:
                    even += 1
                else:
                    odd += 1
            return min(even, odd)
  • 相关阅读:
    CSS关键词的值-currentColor关键字提示文字(当前颜色)
    DOM 对象方法
    CSS三种样式表
    html页面不使用缓存的代码
    DOM-----style属性对照表
    UISwitch属性
    UIImageView属性
    UIView属性
    UIScrollView
    UILabel属性
  • 原文地址:https://www.cnblogs.com/whatyouthink/p/13217923.html
Copyright © 2011-2022 走看看