File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
dsa-solutions/lc-solutions/0300-0399 Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ id: power-of-four
3
+ title: Power Of Four
4
+ sidebar_label: 342-Power-Of-Four
5
+ tags:
6
+ - Math
7
+ - Bit Manupulation
8
+ - Recursion
9
+ ---
10
+
11
+ ## Problem Description
12
+ Given an integer `n`, return `true` if it is a power of four. Otherwise, return `false`.
13
+
14
+ An integer `n` is a power of four, if there exists an integer x such that `n == 4x`.
15
+
16
+
17
+ ### Example
18
+
19
+ **Example 1:**
20
+
21
+ ```
22
+ Input: n = 16
23
+ Output: true
24
+ ```
25
+
26
+ **Example 2:**
27
+ ```
28
+ Input: n = 5
29
+ Output: false
30
+ ```
31
+
32
+ ### Constraints
33
+
34
+ - `-231 <= n <= 231 - 1`
35
+
36
+ ## Solution Approach
37
+
38
+ ### Intuition:
39
+
40
+ To efficiently determine the power of four of the number
41
+
42
+
43
+ ## Solution Implementation
44
+
45
+ ### Code (C++):
46
+
47
+ ```cpp
48
+ class Solution {
49
+ public:
50
+ bool isPowerOfFour(int n) {
51
+ if(n==0) return false;
52
+ else if(n==1) return true;
53
+ return n%4==0 && isPowerOfFour(n/4);
54
+
55
+ }
56
+ };
57
+
58
+ ```
You can’t perform that action at this time.
0 commit comments