diff --git a/231. Power of Two.cpp b/231. Power of Two.cpp new file mode 100644 index 0000000..4bdd369 --- /dev/null +++ b/231. Power of Two.cpp @@ -0,0 +1,7 @@ +class Solution { +public: + bool isPowerOfTwo(int n) { + if (n <= 0) return false; + return (n & (n - 1)) == 0; + } +};