From 10caaa8cff57bf7cb7c1b34a020f2b298c8666b4 Mon Sep 17 00:00:00 2001 From: Aman Kumar <61074175+amanjaiswa@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:35:53 +0530 Subject: [PATCH] Create Power_Of_Two.cpp Example 1: Input: n = 1 Output: true Explanation: 20 = 1 Example 2: Input: n = 16 Output: true Explanation: 24 = 16 Example 3: Input: n = 3 Output: false --- c++/Leetcode_question/Power_Of_Two.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 c++/Leetcode_question/Power_Of_Two.cpp diff --git a/c++/Leetcode_question/Power_Of_Two.cpp b/c++/Leetcode_question/Power_Of_Two.cpp new file mode 100644 index 00000000..fb4baf5e --- /dev/null +++ b/c++/Leetcode_question/Power_Of_Two.cpp @@ -0,0 +1,15 @@ +class Solution { +public: + bool isPowerOfTwo(int n) { + + for (int i = 0; i<=30; i++){ + int ans = pow(2,i); + if(ans == n) + { + return true; + } + + } + return false; + } +};