/*****************************************************问题描述*************************************************
Given an integer, write a function to determine if it is a power of three.
Example 1:
Input: 27
Output: true
Example 2:
Input: 0
Output: false
Example 3:
Input: 9
Output: true
Example 4:
Input: 45
Output: false
判断一个数是否是3的幂
/*****************************************************我的解答*************************************************
/**
* @param {number} n
* @return {boolean}
*/
var isPowerOfThree = function(n) {
if(n <= 0)
{
return false;
}
while(n != 1)
{
if(n % 3 != 0)
{
return false;
}
else
{
n = parseInt(n / 3);
}
}
return true;
};
leetCode刷题记录44_326_Power of Three
最新推荐文章于 2020-03-06 17:41:25 发布