Skip to content

Commit 030badd

Browse files
zhouboyi1998zhouboyi
authored andcommitted
docs(note): 添加题解:326. 3 的幂
1 parent 6271dbb commit 030badd

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

markdown/easy/0326.3的幂.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<h1 style="text-align: center;"> <span style="color: #00AF9B;">326. 3 的幂</span> </h1>
2+
3+
### 🚀 LeetCode
4+
5+
<base target="_blank">
6+
7+
<span style="color: #00AF9B;">**Easy**</span> [**https://leetcode.cn/problems/power-of-three/**](https://leetcode.cn/problems/power-of-three/)
8+
9+
---
10+
11+
### ❓ Description
12+
13+
<br/>
14+
15+
给定一个整数,写一个函数来判断它是否是 `3` 的幂次方。
16+
17+
如果是,返回 `true`;否则,返回 `false`
18+
19+
整数 `n``3` 的幂次方需满足:存在整数 `x` 使得 `n == 3^x`
20+
21+
<br/>
22+
23+
**示例 1:**
24+
25+
```
26+
输入: n = 27
27+
输出: true
28+
```
29+
30+
**示例 2:**
31+
32+
```
33+
输入: n = 0
34+
输出: false
35+
```
36+
37+
**示例 3:**
38+
39+
```
40+
输入: n = 9
41+
输出: true
42+
```
43+
44+
**示例 4:**
45+
46+
```
47+
输入: n = 45
48+
输出: false
49+
```
50+
51+
<br/>
52+
53+
**提示:**
54+
55+
* `-2^31 <= n <= 2^31 - 1`
56+
57+
<br/>
58+
59+
**进阶:** 你能不使用循环或者递归来完成本题吗?
60+
61+
---
62+
63+
### ❗ Solution
64+
65+
<br/>
66+
67+
#### Java
68+
69+
```
70+
class Solution {
71+
public boolean isPowerOfThree(int n) {
72+
while (n > 1 && n % 3 == 0) {
73+
n /= 3;
74+
}
75+
return n == 1;
76+
}
77+
}
78+
```

markdown/hello/0000.Hello.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
| <span style="color: #00AF9B;">**Easy**</span> | [**0258.各位相加**](../easy/0258.各位相加.md) |
7676
| <span style="color: #FFB822;">**Medium**</span> | [**0289.生命游戏**](../medium/0289.生命游戏.md) |
7777
| <span style="color: #00AF9B;">**Easy**</span> | [**0292.Nim游戏**](../easy/0292.Nim游戏.md) |
78+
| <span style="color: #00AF9B;">**Easy**</span> | [**0326.3的幂**](../easy/0326.3的幂.md) |
7879
| <span style="color: #00AF9B;">**Easy**</span> | [**0374.猜数字大小**](../easy/0374.猜数字大小.md) |
7980
| <span style="color: #FFB822;">**Medium**</span> | [**0397.整数替换**](../medium/0397.整数替换.md) |
8081
| <span style="color: #FFB822;">**Medium**</span> | [**0413.等差数列划分**](../medium/0413.等差数列划分.md) |

0 commit comments

Comments
 (0)