8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6a1186a commit 8035e5aCopy full SHA for 8035e5a
problems/326-power-of-three.md
@@ -13,13 +13,35 @@
13
## 代码
14
15
```php
16
+
17
class Solution {
18
19
/**
20
* @param Integer $n
21
* @return Boolean
22
*/
23
function isPowerOfThree($n) {
24
+ // 方法1,递归
25
+ if ($n <= 0) {
26
+ return false;
27
+ }
28
+ if ($n == 1) {
29
+ return true;
30
31
+ if (($n % 3) !== 0) {
32
33
34
+ return $this->isPowerOfThree($n/3);
35
+/*
36
+ // 方法2:循环取余
37
+ while ($n && $n % 3 == 0) {
38
+ $n = $n / 3;
39
40
+ return $n == 1;
41
+ */
42
43
44
+ // 方法3:乘法
45
$a = 1;
46
while($a <= $n){
47
if ($a == $n) {
@@ -28,6 +50,9 @@ class Solution {
50
$a *= 3;
51
}
52
return false;
53
+*/
54
55
56
57
58
```
0 commit comments