Skip to content

Commit 76ec085

Browse files
authored
Create 1475. Final Prices With a Special Discount in a Shop (#665)
2 parents 00e9d0f + 3c8b788 commit 76ec085

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
vector<int> finalPrices(vector<int>& prices) {
4+
int n = prices.size();
5+
vector<int> ans(prices.begin(), prices.end());
6+
for (int i = 0; i < n; i++) {
7+
for (int j = i + 1; j < n; j++) {
8+
if (prices[j] <= prices[i]) {
9+
ans[i] = prices[i] - prices[j];
10+
break;
11+
}
12+
}
13+
}
14+
return ans;
15+
}
16+
};

0 commit comments

Comments
 (0)