From 78da257824d7736fb007fdec43041001bdb40275 Mon Sep 17 00:00:00 2001 From: zhaocchen <zhaocchen@163.com> Date: Mon, 28 Jun 2021 20:14:09 +0800 Subject: [PATCH] feat: add typescript solution to lc problem: No.1913.Maximum Product Difference Between Two Pairs --- .../README.md | 15 +++++++++++++++ .../README_EN.md | 15 +++++++++++++++ .../Solution.js | 10 ++++++++++ 3 files changed, 40 insertions(+) create mode 100644 solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/Solution.js diff --git a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md index b3943e945949a..3d0b2e8ea0acb 100644 --- a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md +++ b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md @@ -66,6 +66,21 @@ ``` +### **JavaScript** + +```js +/** + * @param {number[]} nums + * @return {number} + */ +var maxProductDifference = function(nums) { + nums.sort((a, b) => a - b); + let n = nums.length; + let ans = nums[n - 1] * nums[n - 2] - nums[0] * nums[1]; + return ans; +}; +``` + ### **...** ``` diff --git a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md index e7dac423a66f9..6df8e7e78a107 100644 --- a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md +++ b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md @@ -87,6 +87,21 @@ The product difference is (9 * 8) - (2 * 4) = 64. ``` +### **JavaScript** + +```js +/** + * @param {number[]} nums + * @return {number} + */ +var maxProductDifference = function(nums) { + nums.sort((a, b) => a - b); + let n = nums.length; + let ans = nums[n - 1] * nums[n - 2] - nums[0] * nums[1]; + return ans; +}; +``` + ### **...** ``` diff --git a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/Solution.js b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/Solution.js new file mode 100644 index 0000000000000..56b164fb5876d --- /dev/null +++ b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/Solution.js @@ -0,0 +1,10 @@ +/** + * @param {number[]} nums + * @return {number} + */ + var maxProductDifference = function(nums) { + nums.sort((a, b) => a - b); + let n = nums.length; + let ans = nums[n - 1] * nums[n - 2] - nums[0] * nums[1]; + return ans; +}; \ No newline at end of file