Skip to content

Commit 5902fb9

Browse files
authored
Merge pull request codeharborhub#2942 from Ishitamukherjee2004/main
Solution of 342 (LC No.) is added
2 parents bedbf5a + ea4c20a commit 5902fb9

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
```

0 commit comments

Comments
 (0)