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 6a1186a

Browse files
committed
Feat: 326
1 parent f2fedad commit 6a1186a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

‎problems/326-power-of-three.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## 题目
2+
3+
326. 3的幂
4+
5+
给定一个整数,写一个函数来判断它是否是 3 的幂次方。如果是,返回 true ;否则,返回 false 。
6+
7+
整数 n 是 3 的幂次方需满足:存在整数 x 使得 n == 3x
8+
9+
* 进阶:你能不使用循环或者递归来完成本题吗?
10+
11+
## 思路
12+
13+
## 代码
14+
15+
```php
16+
class Solution {
17+
18+
/**
19+
* @param Integer $n
20+
* @return Boolean
21+
*/
22+
function isPowerOfThree($n) {
23+
$a = 1;
24+
while($a <= $n){
25+
if ($a == $n) {
26+
return true;
27+
}
28+
$a *= 3;
29+
}
30+
return false;
31+
}
32+
}
33+
```

0 commit comments

Comments
(0)

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