1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
powerful-integers.py 759 Bytes
一键复制 编辑 原始数据 按行查看 历史
kamyu 提交于 6年前 . Create powerful-integers.py
# Time: O((logn)^2), n is the bound
# Space: O(r), r is the size of the result
import math
class Solution(object):
def powerfulIntegers(self, x, y, bound):
"""
:type x: int
:type y: int
:type bound: int
:rtype: List[int]
"""
result = set()
log_x = int(math.floor(math.log(bound) / math.log(x)))+1 if x != 1 else 1
log_y = int(math.floor(math.log(bound) / math.log(y)))+1 if y != 1 else 1
pow_x = 1
for i in xrange(log_x):
pow_y = 1
for j in xrange(log_y):
val = pow_x + pow_y
if val <= bound:
result.add(val)
pow_y *= y
pow_x *= x
return list(result)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

搜索帮助