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 78714f8

Browse files
committedJan 9, 2020
Add solution #970
1 parent cfe0e96 commit 78714f8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
 

‎solutions/0970-powerful-integers.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* 970. Powerful Integers
3+
* https://leetcode.com/problems/powerful-integers/
4+
* Difficulty: Easy
5+
*
6+
* Given two positive integers x and y, an integer
7+
* is powerful if it is equal to x^i + y^j for some
8+
* integers i >= 0 and j >= 0.
9+
*
10+
* Return a list of all powerful integers that have
11+
* value less than or equal to bound.
12+
*
13+
* You may return the answer in any order. In your
14+
* answer, each value should occur at most once.
15+
*/
16+
17+
/**
18+
* @param {number} x
19+
* @param {number} y
20+
* @param {number} bound
21+
* @return {number[]}
22+
*/
23+
var powerfulIntegers = function(x, y, bound) {
24+
const result = new Set();
25+
26+
for (let i = 1; i < bound; i *= x) {
27+
for (let j = 1; i + j <= bound; j *= y) {
28+
result.add(i + j);
29+
30+
if (y === 1) { break };
31+
}
32+
33+
if (x === 1) { break };
34+
}
35+
36+
return Array.from(result);
37+
};

0 commit comments

Comments
 (0)
Please sign in to comment.