您的位置:首页 > 其它

Math-326-Power of Three

2018-01-26 20:56 134 查看
Description:

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?

Solution:

class Solution {
public boolean isPowerOfThree(int n) {
while(n > 1){
if(n % 3 != 0) return false;
n /= 3;
}
return n == 1;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: