Skip to content

Commit ebdd01b

Browse files
authored
Update check-if-number-is-a-sum-of-powers-of-three.cpp
1 parent 9ee6114 commit ebdd01b

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

C++/check-if-number-is-a-sum-of-powers-of-three.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
class Solution {
55
public:
66
bool checkPowersOfThree(int n) {
7-
while (n) {
8-
if (n % 3 == 2) {
9-
return false;
10-
}
11-
n /= 3;
12-
}
13-
return true;
7+
for (; n > 0 && n % 3 != 2; n /= 3);
8+
return n == 0;
149
}
1510
};

0 commit comments

Comments
 (0)