类型:数组
-
- 雪糕的最大数量 💛
https://leetcode-cn.com/problems/maximum-ice-cream-bars/
❓ 数组 costs 表示每支雪糕的价格,一共有现金 coins,问能买几个雪糕。
💡 排序
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: costs.sort() count = 0 for c in costs: if coins < c: return count coins -= c count += 1 return count时间复杂度:O(NlogN),空间复杂度:O(1)