- 链接:
- 问题描述,示例,和提示:
- 代码:
- 题目解析:
- 给定的数组代表的意思是:
- 题目意思:
- 解题思路:
链接: 1217. 玩筹码
问题描述,示例,和提示:
class Solution {
public:
int minCostToMoveChips(vector& position) {
int odd = 0,even = 0;
for(int i = 0;i
if(position[i]%2==1)
odd++;
else
even++;
}
return min(odd,even);
}
};
题目解析:
给定的数组代表的意思是:
举个栗子:
arr = [2,2,2,3,3]
arr[0] = 2---->在2号位置上有一个筹码
arr[0] = 2---->在2号位置上有一个筹码
arr[0] = 2---->在2号位置上有一个筹码
arr[0] = 3---->在3号位置上有一个筹码
arr[0] = 3---->在3号位置上有一个筹码
奇数的位置的筹码移动到奇数位置,所需要的代价是零
奇数的位置的筹码移动到偶数位置,所需要的代价是这个奇数位置上有多少个筹码
同理:偶数也一样
统计奇数位置上有多少个筹码,odd
统计偶数位置上有多少个筹码,even
返回min(odd,even);



