File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments