FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/powerful-integers.py at master · pythonpeixun/LeetCode-Solutions · GitHub
pythonpeixun
/
LeetCode-Solutions
Public
forked from
kamyu104/LeetCode-Solutions
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
powerful-integers.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (24 loc) · 759 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
powerful-integers.py
Copy path
File metadata and controls
27 lines (24 loc) · 759 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# 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
)
Back
|
FazBrowse Home
|
New Git URL