summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-07-24 16:09:53 +0800
committercrupest <crupest@outlook.com>2020-07-24 16:09:53 +0800
commit2f6892459fabb475df9cd7edb140fd2e4c4a0a8d (patch)
tree55d5bda6721852ab160f5a57a66cbb66d7294a06 /cpp
parent2d6e1587a3c2b689c9a318152f776206d2b51b5f (diff)
downloadsolutions-2f6892459fabb475df9cd7edb140fd2e4c4a0a8d.tar.gz
solutions-2f6892459fabb475df9cd7edb140fd2e4c4a0a8d.tar.bz2
solutions-2f6892459fabb475df9cd7edb140fd2e4c4a0a8d.zip
Add problem 231 .
Diffstat (limited to 'cpp')
-rw-r--r--cpp/231.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/cpp/231.cpp b/cpp/231.cpp
new file mode 100644
index 0000000..8861e09
--- /dev/null
+++ b/cpp/231.cpp
@@ -0,0 +1,10 @@
+#include <bitset>
+
+class Solution {
+public:
+ bool isPowerOfTwo(int n) {
+ if (n <= 0) return false;
+ std::bitset<sizeof(n) * 8> bits(n);
+ return bits.count() == 1;
+ }
+};