Skip to content

Latest commit

 

History

History
53 lines (38 loc) · 1.46 KB

_1475. Final Prices With a Special Discount in a Shop.md

File metadata and controls

53 lines (38 loc) · 1.46 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : December 18, 2024

Last updated : December 19, 2024


Related Topics : Array, Stack, Monotonic Stack

Acceptance Rate : 83.11 %


Solutions

Python

class Solution:
    def finalPrices(self, prices: List[int]) -> List[int]:
        return [prices[i] - min([(indx, discount) for indx, discount in enumerate(prices[i + 1 :]) if discount <= prices[i]] + [(inf, 0)], key=lambda x: x[0])[1] for i in range(len(prices))]
class Solution:
    def finalPrices(self, prices: List[int]) -> List[int]:
        output = [-1] * len(prices)

        for i in range(len(prices) - 1, -1, -1) :
            price = prices[i]
            maxx = 0
            for disc in prices[i + 1:] :
                if disc > price :
                    continue
                maxx = disc
                break
            output[i] = price - maxx

        return output