diff options
author | crupest <crupest@outlook.com> | 2020-07-24 16:09:53 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-07-24 16:09:53 +0800 |
commit | 2f6892459fabb475df9cd7edb140fd2e4c4a0a8d (patch) | |
tree | 55d5bda6721852ab160f5a57a66cbb66d7294a06 | |
parent | 2d6e1587a3c2b689c9a318152f776206d2b51b5f (diff) | |
download | solutions-2f6892459fabb475df9cd7edb140fd2e4c4a0a8d.tar.gz solutions-2f6892459fabb475df9cd7edb140fd2e4c4a0a8d.tar.bz2 solutions-2f6892459fabb475df9cd7edb140fd2e4c4a0a8d.zip |
Add problem 231 .
-rw-r--r-- | cpp/231.cpp | 10 |
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;
+ }
+};
|