aboutsummaryrefslogtreecommitdiff
path: root/reordered_power_2.py
diff options
context:
space:
mode:
Diffstat (limited to 'reordered_power_2.py')
-rw-r--r--reordered_power_2.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/reordered_power_2.py b/reordered_power_2.py
new file mode 100644
index 0000000..9318c0c
--- /dev/null
+++ b/reordered_power_2.py
@@ -0,0 +1,27 @@
+# 869. Reordered Power of 2
+from collections import Counter
+
+"""
+you are given an integer 'n'. we reorder the digits in any order (including
+the original order) such that the leading digit is not zero. return true if
+an only if we can do this so that the resulting number is a power of two.
+"""
+
+
+class Solution(object):
+ def reorderedPowerOf2(self, n):
+ """
+ :type n: int
+ :rtype: bool
+ """
+ cnt = Counter(str(n))
+ for i in range(31):
+ if Counter(str(1 << i)) == cnt:
+ return True
+ return False
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.reorderedPowerOf2(1))
+ print(obj.reorderedPowerOf2(10))