1475. Final Prices With a Special Discount in a Shop

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1475

class Solution:
    def finalPrices(self, prices: List[int]) -> List[int]:
        stk = []
        res = prices[:]
        for i in range(len(prices) - 1, -1, -1):
            while stk and prices[stk[-1]] > prices[i]:
                stk.pop()
            if stk:
                res[i] -= prices[stk[-1]]
            stk.append(i)
        return res