From d8f4060a4c7376e682ff7baf4bad8cbfaa76ec9d Mon Sep 17 00:00:00 2001 From: ADITYA PATHAK <43406934+paditya99@users.noreply.github.com> Date: Mon, 3 Oct 2022 16:16:53 +0530 Subject: [PATCH] Added CPP solution for LeetCode question of Power of Four --- .../C++/PowerOfFour.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Program's_Contributed_By_Contributors/C++/PowerOfFour.cpp diff --git a/Program's_Contributed_By_Contributors/C++/PowerOfFour.cpp b/Program's_Contributed_By_Contributors/C++/PowerOfFour.cpp new file mode 100644 index 0000000000..b5b659887e --- /dev/null +++ b/Program's_Contributed_By_Contributors/C++/PowerOfFour.cpp @@ -0,0 +1,30 @@ +class Solution { +public: + double value4(double d) +{ + return (log2(d))/2; +} +bool is_integer(float k) +{ + return std::floor(k) == k; +} + bool isPowerOfFour(int n) { + if(n<=0){ + return false; + } + if(n==1){ + return true; + } + if(n%4!=0){ + return false; + } + else{ + if(is_integer(value4(n))){ + return true; + } + else{ + return false; + } + } + } +}; \ No newline at end of file