Movatterモバイル変換


[0]ホーム

URL:


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

Commitec5a38e

Browse files
add 1780
1 parent65f3624 commitec5a38e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1780|[Check if Number is a Sum of Powers of Three](https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1780.java)||Medium|Math, Backtracking, Recursion|
1112
|1779|[Find Nearest Point That Has the Same X or Y Coordinate](https://leetcode.com/problems/find-nearest-point-that-has-the-same-x-or-y-coordinate/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1779.java)||Easy|Array|
1213
|1774|[Closest Dessert Cost](https://leetcode.com/problems/closest-dessert-cost/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1774.java)||Medium|Greedy|
1314
|1773|[Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1773.java)||Easy|Array, String|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.ArrayList;
4+
importjava.util.List;
5+
6+
publicclass_1780 {
7+
publicstaticclassSolution1 {
8+
publicbooleancheckPowersOfThree(intn) {
9+
List<Integer>powers =newArrayList<>();
10+
intpower =1;
11+
for (inti =1;power <=n;i++) {
12+
powers.add(power);
13+
power = (int)Math.pow(3,i);
14+
}
15+
inti =powers.size() -1;
16+
while (n >0 &&i >=0) {
17+
if (n -powers.get(i) >0) {
18+
n -=powers.get(i--);
19+
}elseif (n -powers.get(i) ==0) {
20+
returntrue;
21+
}else {
22+
i--;
23+
}
24+
}
25+
returnn ==0;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp