File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Time: O((logn)^2)
2
+ # Space: O(logn)
3
+
4
+ # Starting with a positive integer N,
5
+ # we reorder the digits in any order (including the original order)
6
+ # such that the leading digit is not zero.
7
+ #
8
+ # Return true if and only if we can do this in a way
9
+ # such that the resulting number is a power of 2.
10
+ #
11
+ # Example 1:
12
+ #
13
+ # Input: 1
14
+ # Output: true
15
+ # Example 2:
16
+ #
17
+ # Input: 10
18
+ # Output: false
19
+ # Example 3:
20
+ #
21
+ # Input: 16
22
+ # Output: true
23
+ # Example 4:
24
+ #
25
+ # Input: 24
26
+ # Output: false
27
+ # Example 5:
28
+ #
29
+ # Input: 46
30
+ # Output: true
31
+ #
32
+ # Note:
33
+ # - 1 <= N <= 10^9
34
+
35
+ class Solution (object ):
36
+ def reorderedPowerOf2 (self , N ):
37
+ """
38
+ :type N: int
39
+ :rtype: bool
40
+ """
41
+ count = collections .Counter (str (N ))
42
+ return any (count == collections .Counter (str (1 << i ))
43
+ for i in xrange (31 ))
You can’t perform that action at this time.
0 commit comments