Skip to content

Commit 5c92bb7

Browse files
committed
Time: 0 ms (100%), Space: 7.8 MB (67.84%) - LeetHub
1 parent 6ab531a commit 5c92bb7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
bool checkPowersOfThree(int n) {
4+
int x = 1;
5+
while (x * 3 <= n) x *= 3;
6+
while (x > 0) {
7+
if (x <= n) {
8+
n -= x;
9+
}
10+
x /= 3;
11+
}
12+
return n == 0;
13+
}
14+
};

0 commit comments

Comments
 (0)