Skip to content

Commit a3d6588

Browse files
committed
Dec 18
1 parent 9af362a commit a3d6588

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def finalPrices(self, prices: List[int]) -> List[int]:
6+
result = [price for price in prices]
7+
stack = []
8+
for idx, price in enumerate(prices):
9+
while stack and prices[stack[-1]] >= price:
10+
result[stack.pop()] -= price
11+
stack.append(idx)
12+
return result
13+
14+
15+
def main():
16+
prices = [8, 4, 6, 2, 3]
17+
assert Solution().finalPrices(prices) == [4, 2, 4, 2, 3]
18+
19+
prices = [1, 2, 3, 4, 5]
20+
assert Solution().finalPrices(prices) == [1, 2, 3, 4, 5]
21+
22+
prices = [10, 1, 1, 6]
23+
assert Solution().finalPrices(prices) == [9, 0, 1, 6]
24+
25+
26+
if __name__ == '__main__':
27+
main()

2024-12-December-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
| December 15 | [1792. Maximum Average Pass Ratio](https://leetcode.com/problems/maximum-average-pass-ratio/) | Medium | Unsolved |
2121
| December 16 | [3264. Final Array State After K Multiplication Operations I](https://leetcode.com/problems/final-array-state-after-k-multiplication-operations-i/) | Easy | Solved |
2222
| December 17 | [2182. Construct String With Repeat Limit](https://leetcode.com/problems/construct-string-with-repeat-limit/) | Medium | Solved |
23-
| December 18 | []() | | |
23+
| December 18 | [1475. Final Prices With a Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/) | Easy | Solved |
2424
| December 19 | []() | | |
2525
| December 20 | []() | | |
2626
| December 21 | []() | | |
@@ -38,6 +38,6 @@
3838
## Summary
3939
| Level | Problems | Solved | Unsolved |
4040
| --- | --- | --- | --- |
41-
| Easy | 4 | 4 | 0 |
41+
| Easy | 5 | 5 | 0 |
4242
| Medium | 13 | 8 | 5 |
4343
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)