869. 重新排序得到 2 的幂
为保证权益,题目请参考 869. 重新排序得到 2 的幂(From LeetCode).
解决方案1
Python
python
# 869. 重新排序得到 2 的幂
#
################################################################################
class Solution:
def reorderedPowerOf2(self, n: int) -> bool:
targets = set()
for i in range(32):
targets.add("".join(sorted(str(2 ** i))))
# targets = {
# "23",
# "01466788",
# "2",
# "0112344778",
# "23334455",
# "4",
# "1",
# "256",
# "128",
# "16",
# "11266777",
# "35566",
# "012356789",
# "1234446788",
# "23678",
# "8",
# "0124",
# "13468",
# "0469",
# "234455668",
# "122446",
# "1289",
# "46",
# "011237",
# "0368888",
# "112234778",
# "0248",
# "0145678",
# "125",
# "0134449",
# "0122579",
# "224588",
# }
tmp = "".join(sorted(str(n)))
return tmp in targets
################################################################################
if __name__ == "__main__":
solution = Solution()
print(solution.reorderedPowerOf2(1))
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
47
48
49
50
51
52
53
54
55
56
57
58
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
47
48
49
50
51
52
53
54
55
56
57
58