func maxSatisfaction(s []int) int {
sort.Ints(s)
sum := 0
max := 0
total := 0
for i := len(s) - 1; i >= 0; i-- {
sum += s[i]
total += sum
if total > max {
max = total
} else {
break
}
}
return max
}
[LeetCode][Go] Leetcode 1402. Reducing Dishes
最新推荐文章于 2023-10-22 16:32:32 发布