From b9344c6d30862ef10b7f309dc11fc024bd927e5b Mon Sep 17 00:00:00 2001 From: Qiu-IT Date: Thu, 8 Jun 2023 09:48:23 +0200 Subject: [PATCH] feat: add js solution to lc problem: No.1475 --- .../README.md | 20 +++++++++++++++++++ .../README_EN.md | 20 +++++++++++++++++++ .../Solution.js | 15 ++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/Solution.js diff --git a/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README.md b/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README.md index 9d926bdbca47c..c7ee779960dcb 100644 --- a/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README.md +++ b/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README.md @@ -392,6 +392,26 @@ class Solution { } ``` +### **JavaScript** + +```js +/** + * @param {number[]} prices + * @return {number[]} + */ +var finalPrices = function (prices) { + for (let i = 0; i < prices.length; i++) { + for (let j = i + 1; j < prices.length; j++) { + if (prices[i] >= prices[j]) { + prices[i] -= prices[j]; + break; + } + } + } + return prices; +}; +``` + ### **...** ``` diff --git a/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README_EN.md b/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README_EN.md index 8406eba67118a..002cb1348e8b4 100644 --- a/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README_EN.md +++ b/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/README_EN.md @@ -363,6 +363,26 @@ class Solution { } ``` +### **JavaScript** + +```js +/** + * @param {number[]} prices + * @return {number[]} + */ +var finalPrices = function (prices) { + for (let i = 0; i < prices.length; i++) { + for (let j = i + 1; j < prices.length; j++) { + if (prices[i] >= prices[j]) { + prices[i] -= prices[j]; + break; + } + } + } + return prices; +}; +``` + ### **...** ``` diff --git a/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/Solution.js b/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/Solution.js new file mode 100644 index 0000000000000..9eff2851ec96d --- /dev/null +++ b/solution/1400-1499/1475.Final Prices With a Special Discount in a Shop/Solution.js @@ -0,0 +1,15 @@ +/** + * @param {number[]} prices + * @return {number[]} + */ +var finalPrices = function (prices) { + for (let i = 0; i < prices.length; i++) { + for (let j = i + 1; j < prices.length; j++) { + if (prices[i] >= prices[j]) { + prices[i] -= prices[j]; + break; + } + } + } + return prices; +};