Skip to content

Commit c12ca62

Browse files
committed
Power of Three
1 parent fc4f76c commit c12ca62

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

LeetCode/power-of-three.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// https://leetcode.com/problems/power-of-three/
2+
3+
class Solution
4+
{
5+
public:
6+
bool isPowerOfThree(int n)
7+
{
8+
if (n <= 0)
9+
{
10+
return false;
11+
}
12+
13+
while ((n % 3 == 0) && (n > 0))
14+
{
15+
n /= 3;
16+
}
17+
18+
return (n == 1);
19+
}
20+
};

0 commit comments

Comments
 (0)