Skip to content

Commit 8290139

Browse files
committed
Add solution #342
1 parent ad8576d commit 8290139

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
273|[Integer to English Words](./0273-integer-to-english-words.js)|Hard|
7575
283|[Move Zeroes](./0283-move-zeroes.js)|Easy|
7676
326|[Power of Three](./0326-power-of-three.js)|Easy|
77+
342|[Power of Four](./0342-power-of-four.js)|Easy|
7778
345|[Reverse Vowels of a String](./0345-reverse-vowels-of-a-string.js)|Easy|
7879
347|[Top K Frequent Elements](./0347-top-k-frequent-elements.js)|Medium|
7980
349|[Intersection of Two Arrays](./0349-intersection-of-two-arrays.js)|Easy|

solutions/0342-power-of-four.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 342. Power of Four
3+
* https://leetcode.com/problems/power-of-four/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer n, return true if it is a power of four. Otherwise, return false.
7+
*
8+
* An integer n is a power of four, if there exists an integer x such that n == 4x.
9+
*/
10+
11+
/**
12+
* @param {number} n
13+
* @return {boolean}
14+
*/
15+
var isPowerOfFour = function(n) {
16+
if (n > 1) {
17+
while (n % 4 === 0) {
18+
n /= 4
19+
}
20+
}
21+
return n === 1;
22+
};

0 commit comments

Comments
 (0)