Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 05d394c

Browse files
authoredSep 3, 2021
Create 1475-final-prices-with-a-special-discount-in-a-shop.js
1 parent 89bacef commit 05d394c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
 
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number[]} prices
3+
* @return {number[]}
4+
*/
5+
const finalPrices = function(prices) {
6+
const res = [], n = prices.length
7+
for(let i = 0; i < n; i++) {
8+
const cur = prices[i]
9+
let dis = null
10+
for(let j = i + 1; j < n; j++) {
11+
if(prices[j] <= cur) {
12+
dis = prices[j]
13+
break
14+
}
15+
}
16+
res.push(dis == null ? cur : cur - dis)
17+
}
18+
return res
19+
};

0 commit comments

Comments
 (0)
Please sign in to comment.