From 2f6892459fabb475df9cd7edb140fd2e4c4a0a8d Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 24 Jul 2020 16:09:53 +0800 Subject: Add problem 231 . --- cpp/231.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 cpp/231.cpp (limited to 'cpp') 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 + +class Solution { +public: + bool isPowerOfTwo(int n) { + if (n <= 0) return false; + std::bitset bits(n); + return bits.count() == 1; + } +}; -- cgit v1.2.3