Skip to content

Commit c49f44b

Browse files
committed
update: 添加问题“1780.判断一个数字是否可以表示成三的幂的和”的代码(并更新其题解) (#1081)
326: AC.rust+java+go+py+cpp (#1078) cpp - AC,100.00%,43.53% py - AC,100.00%,59.18% go - AC,100.00%,90.00% java - AC,100.00%,75.56% rust - AC,100.00%,-% # 是的,没看错 Signed-off-by: LetMeFly666 <[email protected]>
1 parent 502d623 commit c49f44b

11 files changed

+189
-13
lines changed

.commitmsg

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
326: AC.rust+java+go+py+cpp (#1078)
22

3-
rust - AC,51.11%,100.00%
4-
java - AC,89.67%,5.37%
5-
go - AC,20.00%,41.05%
6-
py - AC,46.89%,5.52%
7-
cpp - AC,25.79%,19.01%
8-
今天(相比于之前)倒着写的
3+
cpp - AC,100.00%,43.53%
4+
py - AC,100.00%,59.18%
5+
go - AC,100.00%,90.00%
6+
java - AC,100.00%,75.56%
7+
rust - AC,100.00%,-% # 是的,没看错
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-14 10:28:59
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-14 18:41:02
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
bool checkPowersOfThree(int n) {
14+
while (n) {
15+
if (n % 3 == 2) {
16+
return false;
17+
}
18+
n /= 3;
19+
}
20+
return true;
21+
}
22+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-14 10:28:59
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-14 18:43:30
6+
*/
7+
package main
8+
9+
func checkPowersOfThree(n int) bool {
10+
for ; n > 0; n /= 3 {
11+
if n % 3 == 2 {
12+
return false
13+
}
14+
}
15+
return true
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-14 10:28:59
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-14 18:44:38
6+
*/
7+
class Solution {
8+
public boolean checkPowersOfThree(int n) {
9+
while (n > 0) {
10+
if (n % 3 == 2) {
11+
return false;
12+
}
13+
n /= 3;
14+
}
15+
return true;
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-08-14 10:28:59
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-08-14 18:43:00
6+
'''
7+
class Solution:
8+
def checkPowersOfThree(self, n: int) -> bool:
9+
while n:
10+
if n % 3 == 2:
11+
return False
12+
n //= 3
13+
return True
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-08-14 10:28:59
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-08-14 18:45:31
6+
*/
7+
impl Solution {
8+
pub fn check_powers_of_three(mut n: i32) -> bool {
9+
while n > 0 {
10+
if n % 3 == 2 {
11+
return false;
12+
}
13+
n /= 3;
14+
}
15+
return true;
16+
}
17+
}

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @LastEditTime: 2025-08-11 22:07:08
66
*/
77
pub struct Solution;
8-
include!("0326-power-of-three_20250813.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("1780-check-if-number-is-a-sum-of-powers-of-three_20250814.rs"); // 这个fileName是会被脚本替换掉的

Solutions/LeetCode 1780.判断一个数字是否可以表示成三的幂的和.md

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,109 @@ public:
134134
#### C++
135135
136136
```cpp
137+
/*
138+
* @Author: LetMeFly
139+
* @Date: 2025-08-14 10:28:59
140+
* @LastEditors: LetMeFly.xyz
141+
* @LastEditTime: 2025-08-14 18:41:02
142+
*/
137143
class Solution {
138144
public:
139145
bool checkPowersOfThree(int n) {
140146
while (n) {
141-
if (n % 3 == 2)
147+
if (n % 3 == 2) {
142148
return false;
149+
}
143150
n /= 3;
144151
}
145152
return true;
146153
}
147154
};
148155
```
149156

150-
> 同步发文于CSDN,原创不易,转载请附上[原文链接](https://blog.letmefly.xyz/2022/12/09/LeetCode%201780.%E5%88%A4%E6%96%AD%E4%B8%80%E4%B8%AA%E6%95%B0%E5%AD%97%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E8%A1%A8%E7%A4%BA%E6%88%90%E4%B8%89%E7%9A%84%E5%B9%82%E7%9A%84%E5%92%8C/)哦~
151-
> Tisfy:[https://letmefly.blog.csdn.net/article/details/128248159](https://letmefly.blog.csdn.net/article/details/128248159)
157+
#### Python
158+
159+
```python
160+
'''
161+
Author: LetMeFly
162+
Date: 2025-08-14 10:28:59
163+
LastEditors: LetMeFly.xyz
164+
LastEditTime: 2025-08-14 18:43:00
165+
'''
166+
class Solution:
167+
def checkPowersOfThree(self, n: int) -> bool:
168+
while n:
169+
if n % 3 == 2:
170+
return False
171+
n //= 3
172+
return True
173+
```
174+
175+
#### Java
176+
177+
```java
178+
/*
179+
* @Author: LetMeFly
180+
* @Date: 2025-08-14 10:28:59
181+
* @LastEditors: LetMeFly.xyz
182+
* @LastEditTime: 2025-08-14 18:44:38
183+
*/
184+
class Solution {
185+
public boolean checkPowersOfThree(int n) {
186+
while (n > 0) {
187+
if (n % 3 == 2) {
188+
return false;
189+
}
190+
n /= 3;
191+
}
192+
return true;
193+
}
194+
}
195+
```
196+
197+
#### Go
198+
199+
```go
200+
/*
201+
* @Author: LetMeFly
202+
* @Date: 2025-08-14 10:28:59
203+
* @LastEditors: LetMeFly.xyz
204+
* @LastEditTime: 2025-08-14 18:43:30
205+
*/
206+
package main
207+
208+
func checkPowersOfThree(n int) bool {
209+
for ; n > 0; n /= 3 {
210+
if n % 3 == 2 {
211+
return false
212+
}
213+
}
214+
return true
215+
}
216+
```
217+
218+
#### Rust
219+
220+
```rust
221+
/*
222+
* @Author: LetMeFly
223+
* @Date: 2025-08-14 10:28:59
224+
* @LastEditors: LetMeFly.xyz
225+
* @LastEditTime: 2025-08-14 18:45:31
226+
*/
227+
impl Solution {
228+
pub fn check_powers_of_three(mut n: i32) -> bool {
229+
while n > 0 {
230+
if n % 3 == 2 {
231+
return false;
232+
}
233+
n /= 3;
234+
}
235+
return true;
236+
}
237+
}
238+
```
239+
240+
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/128248159)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2022/12/09/LeetCode%201780.%E5%88%A4%E6%96%AD%E4%B8%80%E4%B8%AA%E6%95%B0%E5%AD%97%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E8%A1%A8%E7%A4%BA%E6%88%90%E4%B8%89%E7%9A%84%E5%B9%82%E7%9A%84%E5%92%8C)哦~
241+
>
242+
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

Solutions/Other-English-LearningNotes-SomeWords.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,8 @@ categories: [自用]
13581358
|provocation|n. 挑衅,刺激,激怒|
13591359
|dignity|n. 尊重,高贵,庄严,端庄,尊严|
13601360
|commonsense|n. 常识,直觉判断力<br/>adj. 常识的,具有常识的|
1361+
|||
1362+
|solemn|adj. 严肃的,庄严的,正式的,郑重的|
13611363

13621364
+ 这个web要是能设计得可以闭眼(完全不睁眼)键盘控制背单词就好了。
13631365
+ 也许可以加个AI用最近词编故事功能(返回接口中支持标注所使用单词高亮?)

newSolution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Author: LetMeFly
33
Date: 2022-07-03 11:21:14
44
LastEditors: LetMeFly.xyz
5-
LastEditTime: 2025-08-12 22:11:48
5+
LastEditTime: 2025-08-14 18:47:41
66
Command: python newSolution.py 102. 二叉树的层序遍历
77
What's more: 当前仅支持数字开头的题目
88
What's more: 代码结构写的很混乱 - 想单文件实现所有操作
@@ -225,7 +225,7 @@ def refreshPublistTime(solution: str) -> str:
225225
with open("README.md", "r", encoding="utf-8") as f:
226226
readme = f.read()
227227
else:
228-
input(f'手动更新完{solutionName}了吗?: ')
228+
input(f'手动更新完 {solutionName} 了吗?: ')
229229
# TODO: 有空时候可以写个手动更新题解中代码的函数 - 最简单的办法是代码追加到(最后一种方法的)后面然后手动删
230230

231231
def readmeNewLine(readme: str) -> str:

0 commit comments

Comments
 (0)