deno.land / x / masx200_leetcode_test@10.6.5 / final-prices-with-a-special-discount-in-a-shop / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export default function finalPrices(prices: number[]): number[] { const n = prices.length; const ans: number[] = Array.from(prices); const stack: number[] = []; for (let i = n - 1; i >= 0; i--) { while (stack.length && stack[stack.length - 1] > prices[i]) { stack.pop(); }
if (stack.length) ans[i] -= stack[stack.length - 1]; stack.push(prices[i]); } return ans;}
masx200_leetcode_test

Version Info

Tagged at
a year ago