题解:
- 求数组和a 和 goal 的距离
- 每次取最大的limit,如果不能整除 则答案还要加一
class Solution {
public int minElements(int[] nums, int limit, int goal) {
long sum = 0;
for (int num : nums) {
sum+=num;
}
long x = Math.abs(goal - sum);
long ans = x / limit;
if((x % limit) != 0) {
ans++;
}
return (int)ans;
}
}
标签:goal,int,sum,1785,最少,limit,ans,添加
From: https://www.cnblogs.com/eiffelzero/p/16988479.html