From 0a462f448d84f5946c1bf056b047e3af4792b08d Mon Sep 17 00:00:00 2001 From: subho Date: Tue, 28 Oct 2025 23:12:14 +0530 Subject: [PATCH] Implement isPowerOfTwo function in Solution class --- 231. Power of Two.cpp | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 231. Power of Two.cpp 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; + } +};