Advertisement
DeepRest

Minimum Cost of Buying Candies With Discount

Jan 23rd, 2022 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.28 KB | None | 0 0
  1. class Solution:
  2.     def minimumCost(self, cost: List[int]) -> int:
  3.         cost.sort(reverse=True)
  4.         n = len(cost)
  5.         cost.append(0)
  6.         res = 0
  7.         i = 0
  8.         while i < n:
  9.             res += cost[i] + cost[i+1]
  10.             i += 3
  11.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement