All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : December 18, 2024
Last updated : December 19, 2024
Related Topics : Array, Stack, Monotonic Stack
Acceptance Rate : 83.11 %
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