Given an integer, write a function to determine if it is a power of three.
class Solution {
public:
bool isPowerOfThree(int n)
{
int arr[8];
arr[0] = 3;
for(int i=1; i<8; i++)
arr[i] = arr[i-1] * 3;
for(int i=7; i>=0; i--)
{
while(arr[i] <= n && n % arr[i] == 0)
n /= arr[i];
}
return n == 1;
}
};