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 class Solution {
public boolean isPowerOfThree(int n) {
int num=n;
while(num>0&&num%3==0)
num/=3;
return num==1;
}
//return n > 0 && (1162261467 % n == 0);
}

每天一道LeetCode--326. Power of Three的更多相关文章

  1. leetcode 326. Power of Three(不用循环或递归)

    leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...

  2. 39. leetcode 326. Power of Three

    326. Power of Three Given an integer, write a function to determine if it is a power of three. Follo ...

  3. [LeetCode] 326. Power of Three 3的次方数

    Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it ...

  4. LeetCode 326 Power of Three

    Problem: Given an integer, write a function to determine if it is a power of three. Could you do it ...

  5. Java [Leetcode 326]Power of Three

    题目描述: Given an integer, write a function to determine if it is a power of three. Follow up:Could you ...

  6. LeetCode 326 Power of Three(3的幂)(递归、Log函数)

    翻译 给定一个整型数,写一个函数决定它是否是3的幂(翻译可能不太合适-- 跟进: 你能否够不用不论什么循环或递归来完毕. 原文 Given an integer, write a function t ...

  7. leetcode 326 Power of Three (python)

    原题: Given an integer, write a function to determine if it is a power of three. Follow up: Could you ...

  8. Leetcode 326 Power of Three 数论

    判断一个数是否是3的n次幂 这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) =  1162261467)的约数 这种方法是我 ...

  9. [LeetCode] 326. Power of Three + 342. Power of Four

    这两题我放在一起说是因为思路一模一样,没什么值得研究的.思路都是用对数去判断. /** * @param {number} n * @return {boolean} */ var isPowerOf ...

  10. [LeetCode] 231. Power of Two 2的次方数

    Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: ...

随机推荐

  1. Hadoop本地库

    目的 鉴于性能问题以及某些Java类库的缺失,对于某些组件,Hadoop提供了自己的本地实现. 这些组件保存在Hadoop的一个独立的动态链接的库里.这个库在*nix平台上叫libhadoop.so. ...

  2. 关于Struts2的客户端校验的FreeMarker template error!

    把<s:form action="login" namespace="/" validate="true" >改为 <s: ...

  3. CUDA从入门到精通

    http://blog.csdn.net/augusdi/article/details/12833235 CUDA从入门到精通(零):写在前面 在老板的要求下.本博主从2012年上高性能计算课程開始 ...

  4. hdu 5569 matrix dp

    matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5569 D ...

  5. 第十七章,txt文件的写入和读取数据结合练习(C++)

    #include <iostream> #include <fstream> int main(int argc, char** argv) { std::string str ...

  6. Android文件选择器的实例分享

    本文给大家讲解下Android文件选择器的使用.实际上就是获取用户在SD卡中选择的文件或文件夹的路径,这很像C#中的OpenFileDialog控件. 此实例的实现过程很简单,这样可以让大家快速的熟悉 ...

  7. Android Mms 接收信息流程

    信息的接收工作是由底层来完成的,当有一个 新的信息时底层完成接收后会以Intent的方式来通知上层应用,信息的相关内容也包含在Intent当中,Android所支持的信息Intent都定 义在andr ...

  8. 项目中oracle存储过程记录——经常使用语法备忘

    项目中oracle存储过程记录--经常使用语法备忘 项目中须要写一个oracle存储过程,需求是收集一个复杂查询的内容(涉及到多张表),然后把符合条件的记录插入到目标表中.当中原表之中的一个的日期字段 ...

  9. SqlDependency缓存数据库表小案例

    SqlDependency的简介: SqlDependency是outputcache网页缓存的一个参数,它的作用是指定缓存失效的数据库依赖项,可以具体到数据库和表. SqlDependency能解决 ...

  10. Hive官方手册翻译(Getting Started)(转)

    原文:http://slaytanic.blog.51cto.com/2057708/939950 翻译Hive官方文档系列,文中括号中包含 注: 字样的,为我自行标注的,水平有限,翻译不是完美无缺的 ...