桌上有 n 堆力扣币,每堆的数量保存在数组 coins 中。我们每次可以选择任意一堆,拿走其中的一枚或者两枚,求拿完所有力扣币的最少次数。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/na-ying-bi/
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
public class Solution {
public int MinCount(int[] coins) {
int sum=0;
int flag=0;
for(int i=0;i<coins.Length;i++){
while(coins[i]>0){
coins[i]=coins[i]-2;
flag++;
}
sum+=flag;
flag=0;
}
return sum;
}
}