LC.P2171[拿出最少数目的魔法豆] 方法一:排序+枚举12345678910111213class Solution { public long minimumRemoval(int[] beans) { Arrays.sort(beans); long sum = 0; for (int x : beans) sum += x; long ans = sum; int n = beans.length; for (int i = 0; i < n; ++i) { ans = Math.min(ans, sum - (long) beans[i] * (n - i)); } return ans; }} 时间复杂度:$O(nlogn)$ 空间复杂度:$O(logn)$