1010. Powerful Integers
My accepted Python solution to LeetCode problem 1010, Powerful Integers, running in 0ms.
- Difficulty: Medium
- Python
- Runtime 0ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.3MB, accepted 2026-01-02.
class Solution:
def powerfulIntegers(self, x: int, y: int, bound: int) -> List[int]:
result = set()
# Generate all powers of x
powers_x = [1]
if x > 1:
while powers_x[-1] * x <= bound:
powers_x.append(powers_x[-1] * x)
# Generate all powers of y
powers_y = [1]
if y > 1:
while powers_y[-1] * y <= bound:
powers_y.append(powers_y[-1] * y)
# Try all combinations
for px in powers_x:
for py in powers_y:
if px + py <= bound:
result.add(px + py)
return list(result)