LeetCode --- 1217. Minimum Cost to Move Chips to The Same Position 解题报告

Posted 杨鑫newlfe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode --- 1217. Minimum Cost to Move Chips to The Same Position 解题报告相关的知识,希望对你有一定的参考价值。

We have n chips, where the position of the ith chip is position[i].

We need to move all the chips to the same position. In one step, we can change the position of the ith chip from position[i] to:

  • position[i] + 2 or position[i] - 2 with cost = 0.
  • position[i] + 1 or position[i] - 1 with cost = 1.

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

Example 1:

Input: position = [1,2,3]
Output: 1
Explanation: First step: Move the chip at position 3 to position 1 with cost = 0.
Second step: Move the chip at position 2 

以上是关于LeetCode --- 1217. Minimum Cost to Move Chips to The Same Position 解题报告的主要内容,如果未能解决你的问题,请参考以下文章

[leetcode 周赛 157] 1217 玩筹码

算法 LEETCODE 1217. Play with Chips

LeetCode1217 玩筹码(贪心)

LeetCode --- 1217. Minimum Cost to Move Chips to The Same Position 解题报告

LeetCode --- 1217. Minimum Cost to Move Chips to The Same Position 解题报告

Leetcode 动态规划的目标和