-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path970.java
More file actions
51 lines (37 loc) · 1.19 KB
/
970.java
File metadata and controls
51 lines (37 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public List<Integer> powerfulIntegers(int x, int y, int bound) {
List<Integer> ans = new ArrayList<>();
recur(ans,1,1,x,y,bound);
return ans;
}
public void recur(List<Integer> ans,int xp, int yp,int x,int y, int bound){
int cur = xp+yp;
if(cur > bound || ans.contains(cur))
return;
ans.add(cur);
recur(ans,xp*x,yp,x,y,bound);
recur(ans,xp,yp*y,x,y,bound);
}
}
__________________________________________________________________________________________________
sample 32436 kb submission
class Solution {
public List<Integer> powerfulIntegers(int x, int y, int bound) {
Set<Integer> set = new HashSet<>();
for (int a = 1; a <= bound; a *= x) {
for (int b = 1; a + b <= bound; b *= y) {
set.add(a + b);
if (y == 1) {
break;
}
}
if (x == 1) {
break;
}
}
return new ArrayList<>(set);
}
}
__________________________________________________________________________________________________