Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5c904c7

Browse files
committed
342
1 parent 9031f85 commit 5c904c7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎Easy/342. Power of Four/solution.php‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
class Solution
3+
{
4+
/**
5+
* @param Integer $n
6+
* @return Boolean
7+
*/
8+
public function isPowerOfFour($n)
9+
{
10+
if ($n < 1) {
11+
return false;
12+
}
13+
while ($n % 4 == 0) {
14+
$n /= 4;
15+
}
16+
return $n == 1;
17+
}
18+
}
19+
20+
$solution = new Solution();
21+
var_dump($solution->isPowerOfFour(16)); // true
22+
var_dump($solution->isPowerOfFour(5)); // false
23+
var_dump($solution->isPowerOfFour(1)); // true

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /