How Many Apples Can You Put into the Basket
给一组数, 求怎么装能最多, 最多加起来5000. 因为求最多, 所以肯定先装小的.
class Solution {
public int maxNumberOfApples(int[] arr) {
int sum = 0;
for(int n : arr)
sum += n;
Arrays.sort(arr);
int i = arr.length - 1;
while(sum >= 5000){
sum -= arr[i--];
}
return i+1;
}
}