-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path869.ReorderedPowerof2.py
46 lines (37 loc) · 1 KB
/
869.ReorderedPowerof2.py
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
'''
Starting with a positive integer N, we reorder the
digits in any order (including the original order) such
that the leading digit is not zero.
Return true if and only if we can do this in a way such
that the resulting number is a power of 2.
Example:
Input: 1
Output: true
Example:
Input: 10
Output: false
Example:
Input: 16
Output: true
Example:
Input: 24
Output: false
Example:
Input: 46
Output: true
Note:
1. 1 <= N <= 10^9
'''
#Difficulty: Medium
#135 / 135 test cases passed.
#Runtime: 32 ms
#Memory Usage: 14.2 MB
#Runtime: 32 ms, faster than 81.85% of Python3 online submissions for Reordered Power of 2.
#Memory Usage: 14.2 MB, less than 52.82% of Python3 online submissions for Reordered Power of 2.
class Solution:
def reorderedPowerOf2(self, N: int) -> bool:
N = sorted(str(N))
for x in range(30):
if N == sorted(str(2**x)):
return True
return False