From a21a1ae3b8c13b9981afb78b99f91b2a89058ec6 Mon Sep 17 00:00:00 2001 From: zhaocchen Date: Wed, 19 May 2021 09:04:16 +0800 Subject: [PATCH] feat: add javascript solution to lc problem: No.0970.Powerful Integers --- .../0970.Powerful Integers/README.md | 24 +++++++++++++++++++ .../0970.Powerful Integers/README_EN.md | 24 +++++++++++++++++++ .../0970.Powerful Integers/Solution.js | 19 +++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 solution/0900-0999/0970.Powerful Integers/Solution.js diff --git a/solution/0900-0999/0970.Powerful Integers/README.md b/solution/0900-0999/0970.Powerful Integers/README.md index 6f8a3c148a90c..5cc14be692d3e 100644 --- a/solution/0900-0999/0970.Powerful Integers/README.md +++ b/solution/0900-0999/0970.Powerful Integers/README.md @@ -99,6 +99,30 @@ class Solution { } ``` +### **JavaScript** + +```js +/** + * @param {number} x + * @param {number} y + * @param {number} bound + * @return {number[]} + */ +var powerfulIntegers = function(x, y, bound) { + let res = new Set(); + for (let i = 1; i < bound; i *= x) { + for (let j = 1; j < bound; j *= y) { + if ((i + j) <= bound) { + res.add(i + j); + } + if (y == 1) break; + } + if (x == 1) break; + } + return [...res]; +}; +``` + ### **...** ``` diff --git a/solution/0900-0999/0970.Powerful Integers/README_EN.md b/solution/0900-0999/0970.Powerful Integers/README_EN.md index 2e21af3dc26f4..b716c8ac35d04 100644 --- a/solution/0900-0999/0970.Powerful Integers/README_EN.md +++ b/solution/0900-0999/0970.Powerful Integers/README_EN.md @@ -91,6 +91,30 @@ class Solution { } ``` +### **JavaScript** + +```js +/** + * @param {number} x + * @param {number} y + * @param {number} bound + * @return {number[]} + */ +var powerfulIntegers = function(x, y, bound) { + let res = new Set(); + for (let i = 1; i < bound; i *= x) { + for (let j = 1; j < bound; j *= y) { + if ((i + j) <= bound) { + res.add(i + j); + } + if (y == 1) break; + } + if (x == 1) break; + } + return [...res]; +}; +``` + ### **...** ``` diff --git a/solution/0900-0999/0970.Powerful Integers/Solution.js b/solution/0900-0999/0970.Powerful Integers/Solution.js new file mode 100644 index 0000000000000..3947b94c55010 --- /dev/null +++ b/solution/0900-0999/0970.Powerful Integers/Solution.js @@ -0,0 +1,19 @@ +/** + * @param {number} x + * @param {number} y + * @param {number} bound + * @return {number[]} + */ + var powerfulIntegers = function(x, y, bound) { + let res = new Set(); + for (let i = 1; i < bound; i *= x) { + for (let j = 1; j < bound; j *= y) { + if ((i + j) <= bound) { + res.add(i + j); + } + if (y == 1) break; + } + if (x == 1) break; + } + return [...res]; +}; \ No newline at end of file