File tree Expand file tree Collapse file tree 3 files changed +33
-33
lines changed
solution/1400-1499/1475.Final Prices With a Special Discount in a Shop Expand file tree Collapse file tree 3 files changed +33
-33
lines changed Original file line number Diff line number Diff line change @@ -142,17 +142,17 @@ public:
142
142
```go
143
143
func finalPrices(prices []int) []int {
144
144
stk := []int{}
145
- for i := len(prices) - 1; i >= 0; i-- {
146
- x := prices[i]
147
- for len(stk) > 0 && stk[len(stk)-1] > x {
148
- stk = stk[:len(stk)-1]
149
- }
150
- if len(stk) > 0 {
151
- prices[i] -= stk[len(stk)-1]
152
- }
153
- stk = append(stk, x)
154
- }
155
- return prices
145
+ for i := len(prices) - 1; i >= 0; i-- {
146
+ x := prices[i]
147
+ for len(stk) > 0 && stk[len(stk)-1] > x {
148
+ stk = stk[:len(stk)-1]
149
+ }
150
+ if len(stk) > 0 {
151
+ prices[i] -= stk[len(stk)-1]
152
+ }
153
+ stk = append(stk, x)
154
+ }
155
+ return prices
156
156
}
157
157
```
158
158
Original file line number Diff line number Diff line change @@ -143,17 +143,17 @@ public:
143
143
```go
144
144
func finalPrices(prices []int) []int {
145
145
stk := []int{}
146
- for i := len(prices) - 1; i >= 0; i-- {
147
- x := prices[i]
148
- for len(stk) > 0 && stk[len(stk)-1] > x {
149
- stk = stk[:len(stk)-1]
150
- }
151
- if len(stk) > 0 {
152
- prices[i] -= stk[len(stk)-1]
153
- }
154
- stk = append(stk, x)
155
- }
156
- return prices
146
+ for i := len(prices) - 1; i >= 0; i-- {
147
+ x := prices[i]
148
+ for len(stk) > 0 && stk[len(stk)-1] > x {
149
+ stk = stk[:len(stk)-1]
150
+ }
151
+ if len(stk) > 0 {
152
+ prices[i] -= stk[len(stk)-1]
153
+ }
154
+ stk = append(stk, x)
155
+ }
156
+ return prices
157
157
}
158
158
```
159
159
Original file line number Diff line number Diff line change 1
1
func finalPrices (prices []int ) []int {
2
2
stk := []int {}
3
- for i := len (prices ) - 1 ; i >= 0 ; i -- {
4
- x := prices [i ]
5
- for len (stk ) > 0 && stk [len (stk )- 1 ] > x {
6
- stk = stk [:len (stk )- 1 ]
7
- }
8
- if len (stk ) > 0 {
9
- prices [i ] -= stk [len (stk )- 1 ]
10
- }
11
- stk = append (stk , x )
12
- }
13
- return prices
3
+ for i := len (prices ) - 1 ; i >= 0 ; i -- {
4
+ x := prices [i ]
5
+ for len (stk ) > 0 && stk [len (stk )- 1 ] > x {
6
+ stk = stk [:len (stk )- 1 ]
7
+ }
8
+ if len (stk ) > 0 {
9
+ prices [i ] -= stk [len (stk )- 1 ]
10
+ }
11
+ stk = append (stk , x )
12
+ }
13
+ return prices
14
14
}
You can’t perform that action at this time.
0 commit comments