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
orposition[i] - 2
withcost = 0
.position[i] + 1
orposition[i] - 1
withcost = 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 1217. Play with Chips
LeetCode --- 1217. Minimum Cost to Move Chips to The Same Position 解题报告
LeetCode --- 1217. Minimum Cost to Move Chips to The Same Position 解题报告