题目描述:
桌上有 n 堆力扣币,每堆的数量保存在数组 coins 中。我们每次可以选择任意一堆,拿走其中的一枚或者两枚,求拿完所有力扣币的最少次数。
输入:
[4,2,1]
[2,3,10]
输出:
4
8
题意:
题目描述
题解:
简单贪心
只有两种操作,要么拿一个要么拿两个
对于每一个数,大于等于2的时候全部按照2拿,最优
代码:
class Solution {
public int minCount(int[] coins) {
int ans = 0;
int len = coins.length;
for(int i = 0; i < len; i ++){
ans += coins[i] / 2;
if(coins[i] % 2 != 0){
ans ++;
}
}
return ans;
}
}