Skip to content

Commit c9d2b62

Browse files
authored
Create minimum-cost-of-buying-candies-with-discount.py
1 parent 19db03d commit c9d2b62

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Time: O(nlogn)
2+
# Space: O(1)
3+
4+
# greedy
5+
class Solution(object):
6+
def minimumCost(self, cost):
7+
"""
8+
:type cost: List[int]
9+
:rtype: int
10+
"""
11+
cost.sort(reverse=True)
12+
return sum(x for i, x in enumerate(cost) if i%3 != 2)

0 commit comments

Comments
 (0)