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 | e703e4c1fcef4d94a3c5fa2ef2dba4c6b5eb7591 (patch) | |
| tree | a1293e6e132cf4b1a54b45a81aae004378ccecbd /works/solutions/cpp | |
| parent | 4934c181dbb4db9df543b665dee0951e4d235051 (diff) | |
| download | crupest-e703e4c1fcef4d94a3c5fa2ef2dba4c6b5eb7591.tar.gz crupest-e703e4c1fcef4d94a3c5fa2ef2dba4c6b5eb7591.tar.bz2 crupest-e703e4c1fcef4d94a3c5fa2ef2dba4c6b5eb7591.zip  | |
import(solutions): Add problem 231 .
Diffstat (limited to 'works/solutions/cpp')
| -rw-r--r-- | works/solutions/cpp/231.cpp | 10 | 
1 files changed, 10 insertions, 0 deletions
diff --git a/works/solutions/cpp/231.cpp b/works/solutions/cpp/231.cpp new file mode 100644 index 0000000..8861e09 --- /dev/null +++ b/works/solutions/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;
 +    }
 +};
  | 
