原题
Given an integer, write a function to determine if it is a power of three.
Follow up:
Could you do it without using any loop / recursion?
代码实现
public boolean isPowerOfThree(int n)
{
int powcnt = 0;
if(Math.Pow(3,19)<Int32.MaxValue && Math.Pow(3,20)>Int32.MaxValue)
powcnt = 19;
return ( n>0 && Math.Pow(3,19)%n==0);
}
leetcode-solution库
leetcode算法题目解决方案每天更新在github库中,欢迎感兴趣的朋友加入进来,也欢迎star,或pull request。https://github.com/jackzhenguo/leetcode-csharp