每天一道LeetCode--326. Power of Three
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的更多相关文章
- leetcode 326. Power of Three(不用循环或递归)
leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...
- 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 ...
- [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 ...
- 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 ...
- 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 ...
- LeetCode 326 Power of Three(3的幂)(递归、Log函数)
翻译 给定一个整型数,写一个函数决定它是否是3的幂(翻译可能不太合适-- 跟进: 你能否够不用不论什么循环或递归来完毕. 原文 Given an integer, write a function t ...
- 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 ...
- Leetcode 326 Power of Three 数论
判断一个数是否是3的n次幂 这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) = 1162261467)的约数 这种方法是我 ...
- [LeetCode] 326. Power of Three + 342. Power of Four
这两题我放在一起说是因为思路一模一样,没什么值得研究的.思路都是用对数去判断. /** * @param {number} n * @return {boolean} */ var isPowerOf ...
- [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: ...
随机推荐
- SimpleUrlHandlerMapping用法
SimpleUrlHandlerMapping是Spring MVC中适用性最强的Handler Mapping类,允许明确指定URL模式和Handler的映射关系.有两种方式声明SimpleUrlH ...
- 根据powerdesigner的OO模型生成C#代码
2007-05-15 08:34:11| 分类: 转贴部分 | 标签:学习帖子 |字号 订阅 习惯了用Powerdesigner设计数据库模型,XDE设计类图.因此我一般的设计方法是用PD做分析模 ...
- Java中throws和throw的区别讲解
当然,你需要明白异常在Java中式以一个对象来看待.并且所有系统定义的编译和运行异常都可以由系统自动抛出,称为标准异常,但是一般情况下Java 强烈地要求应用程序进行完整的异常处理,给用户友好的提示, ...
- Arrays.sort(new String[]{"aaa"}); 排序方法
private static void mergeSort(Object[] src, Object[] dest, int low, int high, int off) { int length ...
- ireport启动闪退问题
安装好ireport之后,双击ireport.exe启动程序只是掠过启动画面便毫无反应, 后来在网上找了下解决方法,才知道只因为ireport与jdk8不兼容, 于是下载了jdk6,并在ireport ...
- jquery hasClass()、is() 多个
一..hasClass() hasClass()方法是用来检查被选择的元素是否包含指定的class名,其语法: $(selector).hasClass("className"); ...
- MySQL的数据库引擎的类型及区别
MySQL的数据库引擎的类型 你能用的数据库引擎取决于mysql在安装的时候是如何被编译的.要添加一个新的引擎,就必须重新编译MYSQL.在缺省情况下,MYSQL支持三个引擎:ISAM.MYISAM和 ...
- C语言第三节关键字、标识符、注释
学习语法之前的提醒 C语言属于一门高级语言,其实,所有高级语言的基本语法组成部分都是一样的,只是表现形式不太一样 就好像亚洲人和非洲人,大家都有人类的结构:2只 手.2只脚.1个头,只是他们外表不太一 ...
- Last non-zero Digit in N!
Problem Description The expression N!, read as "N factorial," denotes the product of the f ...
- struts2拦截器源码分析
前面博客我们介绍了开发struts2应用程序的基本流程(开发一个struts2的实例),通过前面我们知道了struts2实现请求转发和配置文件加载都是拦截器进行的操作,这也就是为什么我们要在web.x ...