# 商店Leetcode解决方案中的最终价格具有特别折扣

`[8,4,6,2,3]`
`[4,2,4,2,3]`

## 商店Leetcode解决方案中具有特别折扣的最终价格代码

### C ++代码

```#include <bits/stdc++.h>
using namespace std;

vector<int> finalPrices(vector<int>& prices) {
stack<int> s;
s.push(0);
for(int i=1;i<prices.size();i++){
while(!s.empty() && prices[s.top()] >= prices[i])prices[s.top()] -= prices[i], s.pop();
s.push(i);
}
return prices;
}

int main() {
vector<int> prices = {8,4,6,2,3};
vector<int> output = finalPrices(prices);
for(int i=0;i<output.size();i++)
cout<<output[i]<<" ";
}
```
`4 2 4 2 3`

### Java代码

```import java.util.*;
import java.io.*;

class Main {
public static int[] finalPrices(int[] prices) {
Stack<Integer> s = new Stack<>();
for (int i = 0; i < prices.length; i++) {
while (!s.isEmpty() && prices[s.peek()] >= prices[i])
prices[s.pop()] -= prices[i];
s.push(i);
}
return prices;
}

public static void main(String[] args) {
int[] prices = {8,4,6,2,3};
int[] output = finalPrices(prices);
for(int i=0;i<output.length;i++)
System.out.print(output[i]+" ");
}
}
```
`4 2 4 2 3`