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:
142142```go
143143func finalPrices(prices []int) []int {
144144 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
156156}
157157```
158158
Original file line number Diff line number Diff line change @@ -143,17 +143,17 @@ public:
143143```go
144144func finalPrices(prices []int) []int {
145145 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
157157}
158158```
159159
Original file line number Diff line number Diff line change 11func finalPrices (prices []int ) []int {
22 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
1414}
You can’t perform that action at this time.
0 commit comments