题目好难理解,看了各位大神们的解释才懂了要求做什么。比如说[2,2,2,3,3] 的意思是[index == 2的位置上有一个chip,index == 2的位置上有一个chip,index == 2的位置上有一个chip, index == 3的位置上有一个chip, index == 3的位置上有一个chip].  那其实问题就成了,奇数index上的chips,无论挪到哪里都是不cost的,因为每次挪2位。同理,偶数index上的chips也一样。问题就成了,把奇数位上的全部chips挪到同一个奇数位上,把偶数位上的全部chips挪到同一个偶数位上,其这两个位置相邻。最后看哪位上的chips少,就把少的挪到多的上。

class Solution:def minCostToMoveChips(self, position: List[int]) -> int:evenpos = 0totalchips = len(position)for index, pos in enumerate(position):if pos % 2 == 0:evenpos += 1oddpos = totalchips - evenposreturn min(oddpos, evenpos)

Leetcode 1217. Minimum Cost to Move Chips to The Same Position [Python]相关推荐

  1. leetcode 1217. Minimum Cost to Move Chips to The Same Position | 1217. 玩筹码(Java)

    题目 题解 所有的 chips,要么在奇数位置,要么在偶数位置 class Solution {public int minCostToMoveChips(int[] position) {int p ...

  2. leetcode 983. Minimum Cost For Tickets | 983. 最低票价(动态规划)

    题目 https://leetcode.com/problems/minimum-cost-for-tickets/ 题解 没想出来,看了官方题解,难点在于如何列出 dp 的状态转移方程.我没想到它的 ...

  3. leetcode 1217. Play with Chips 解法 python

    一.问题描述 There are some chips, and the i-th chip is at position chips[i]. You can perform any of the t ...

  4. 【LeetCode 1000】 Minimum Cost to Merge Stones

    题目描述 There are N piles of stones arranged in a row. The i-th pile has stones[i] stones. A move consi ...

  5. LeetCode 746. Min Cost Climbing Stairs--动态规划--Java,C++,Python解法

    题目地址:Min Cost Climbing Stairs - LeetCode LeetCode 动态规划(Dynamic programming)系列题目:LeetCode 动态规划(Dynami ...

  6. [费用流专题]Going Home,Minimum Cost,工作安排

    文章目录 T1:Going Home 题目 题解 CODE T2:Minimum Cost 题目 题解 CODE T3:工作安排 题解 CODE T1:Going Home 题目 On a grid ...

  7. [Swift]LeetCode1135. 最低成本联通所有城市 | Connecting Cities With Minimum Cost

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  8. POJ 2516 -- Minimum Cost (最小费用最大流, 必须分开建图)

    题目链接 Description Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In ...

  9. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

最新文章

  1. Openssl私建CA
  2. 卷积神经网络CNNs的理解与体会
  3. webpack 单独打包指定JS文件
  4. Uva673 平衡的括号
  5. hive导数据到mysql 自增主键出错_老大问我:“建表为啥还设置个自增 id ?用流水号当主键不正好么?”...
  6. [CE5入门系列1]如何正确安装和初步使用
  7. DayDayUp:互联网江湖大佬那些事(互联网大佬学历一览)
  8. Navisworks API 简单二次开发 (自定义工具条)
  9. python apscheduler 阻塞方式只用一个线程_框架APScheduler在python中调度使用的实例详解...
  10. input子系统基础之按键3——input子系统架构总览
  11. vs已停止工作的解决方案
  12. Eclipse 生成 Jar 包
  13. 单链表的回文判断(O(n)时间复杂度和O(1)的空间复杂度)
  14. 《Flash ActionScript 3.0 动画高级教程》
  15. win下使用VM虚拟机安装Linux系统
  16. apache 中 ServerAlias多个域名绑定同一空间(网站)
  17. atitit。企业组织与软件工程的策略 战略 趋势 原则 attilax 大总结
  18. matlab xrd,波导光学大作业-论文-matlab模拟xrd及分析.doc
  19. 域管理员与本地管理员密码破解
  20. mysql 1205 解决_mysql 1205 ,自动重启数据库

热门文章

  1. Android7.0(mtk)开放root权限,adb root和app root
  2. 简易电梯控制系统设计(两层楼)(
  3. 用卷积神经网络实现笑脸、非笑脸表情识别
  4. php sapi zend,安装php出现make: *** [sapi/cli/php]
  5. android 5.1拍照后图片镜像处理
  6. vue调取电脑摄像头实现拍照功能
  7. 番茄助手(Visual Assist X)过期的应对方法
  8. Unity 动态改变Text字体颜色
  9. 《幸福人生 从心开始》讲座参后感
  10. 处理 web 程序的输入与输出