2024-01-18发表2024-01-18更新LeetCode每日一题几秒读完 (大约92个字)0次访问2171. 拿出最少数目的魔法豆2171. 拿出最少数目的魔法豆 难度: medium 原始链接: https://leetcode.cn/problems/removing-minimum-number-of-magic-beans 标签: 排序, 前缀和 解法一: 排序, 前缀和go1234567891011func minimumRemoval(beans []int) int64 { sort.Ints(beans) var sum int64 = 0 var maxVal int64 = 0 n := len(beans) for i, bean := range beans { sum += int64(bean) maxVal = max(maxVal, int64(n - i) * int64(bean)) } return sum - maxVal}2171. 拿出最少数目的魔法豆https://wuhunyu.top/leetcode/2024/01/removing-minimum-number-of-magic-beans/index.html作者wuhunyu发布于2024-01-18更新于2024-01-18许可协议#前缀和排序