19 lines
448 B
Go
19 lines
448 B
Go
// Package q1475 implements a solution for https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/
|
|
package q1475
|
|
|
|
func finalPrices(prices []int) []int {
|
|
st := make([]int, 0, 1024)
|
|
|
|
for i := len(prices) - 1; i >= 0; i-- {
|
|
p := prices[i]
|
|
for ; len(st) > 0 && st[len(st)-1] > p; st = st[:len(st)-1] {
|
|
}
|
|
if len(st) > 0 {
|
|
prices[i] = p - st[len(st)-1]
|
|
}
|
|
st = append(st, p)
|
|
}
|
|
return prices
|
|
}
|
|
|
|
var _ = finalPrices
|