LeetCode--No.326--Power of Three
2016-06-15 03:06
218 查看
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) {
if (n <= 0)
return false;
else{
while(n % 3 == 0){
n /= 3;
}
if (n==1)
return true;
else
return false;
}
}
}
Follow up:
Could you do it without using any loop / recursion?
public class Solution {
public boolean isPowerOfThree(int n) {
if (n <= 0)
return false;
else{
while(n % 3 == 0){
n /= 3;
}
if (n==1)
return true;
else
return false;
}
}
}
相关文章推荐
- UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现
- 设计模式(一)工厂模式Factory(创建型)
- Sublime3中快捷键的设置
- Combination Sum
- Python \x invalid escape error 和 windows 下的文件路径使用问题
- php类中静态变量与常亮的区别
- Android Studio打包全攻略---从入门到精通
- 四则运算app代码上传GITHUB
- connect函数详解
- nodejs读取图片像素
- IIS设置不合理导致的外网无法访问服务器的解决方法
- 电脑通过vnc控制android 手机
- 【Web】C++ Http -- 记一次使用第三方http请求的问题解决
- BAT纷纷入局,云游戏低调崛起
- LeetCode 357. Count Numbers with Unique Digits(计算无重复数字)
- ios学习路线—Objective-C(MRC)
- IntelliJ IDEA 快捷键和设置
- go环境搭建安装gocode出现mkdir: cannot create directory ‘/usr/local/go/bin/gocode’: Permission denied
- Linux shell 脚本编程学习笔记(echo)
- 继续补充基础难点知识_3