LC.P970[强整数]

方法一:哈希表+枚举

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public List<Integer> powerfulIntegers(int x, int y, int bound) {
Set<Integer> set = new HashSet<>();
for (int i = 1; i <= bound; i *= x) {
for (int j = 1; i + j <= bound; j *= y) {
set.add(i + j);
if (y == 1) break;
}
if (x == 1) break;
}
return new ArrayList<>(set);
}
}