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