LeetCode----326. Power of Three(Java)
package isPowerOfThree326;
/*
Given an integer, write a function to determine if it is a power of three.
*/
public class Solution {
/*
//题目理解错误,理解成3次开方
public static boolean isPowerOfThree(int n) {
if (n==1)
return true;
else{
for(int i=2;i<=Math.sqrt(n);i++){
if(n%i==0){
n=n/i;
if(n%i==0){
n=n/i;
if (n%i==0){
n=n/i;
return isPowerOfThree(n);
}
else
return false;
}
return false;
}
}
return false;
}
}
*/
public static boolean isPowerOfThree(int n){
if (n==1)
return true;
else if (n==0)
return false;
else if (n%3==0){
n=n/3;
return isPowerOfThree(n);
}
else
return false; }
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(isPowerOfThree(-3));
} }
LeetCode----326. Power of Three(Java)的更多相关文章
- 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 ...
- 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的次方数
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 ...
- 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: ...
随机推荐
- QWeb、Widget继承
对于Odoo前端来说,所有的js对象都是继承自openerp.web.Class这个类,然后由此派生出Widget,由Widget派生出其他诸如View等可视化部件,结合QWeb,我们可以实现对现有部 ...
- mysql中profile的使用
1.profile在mysql5.0.37及其以上版本中可用 2.查看profile是否可用SELECT @@profiling;来查看是否已经启用profile,如果profilng值为0,可以通过 ...
- javascript小实例,多种方法实现数组去重问题
废话不多说,直接拿干货! 先说说这个实例的要求:写一个方法实现数组的去重.(要求:执行方法,传递一个数组,返回去重后的新数组,原数组不变,实现过程中只能用一层循环,双层嵌套循环也可写,只做参考): 先 ...
- sublime添加PHP语法检查
1.找到php文件目录 如E:\xampp\php 放到环境变量的path中 2.sublime 工具-编译系统-新编译系统 { "cmd": ["php& ...
- iOS下Html页面中input获取焦点弹出键盘时挡住input解决方案—scrollIntoView()
问题描述 iOS系统下,移动web页面,inpu获取焦点弹出系统虚拟键盘时,偶尔会出现挡住input的情况,尽管概率不大,但是十分影响用户体验. 问题重现 原始页面:页面中有header.main.f ...
- Decimal To Fraction 小数转换成分数
以0.25为例, 0.25 * 100 = 25, 求25 和 100 的最大公约数gcd. 25/gcd 为分子. 100/gcd为分母. //小数转分数 //0.3 -> 3/10, 0.2 ...
- Linux Samba服务器配置
Linux系统默认已经安装了Samba,但是没有安装Samba服务: 1,先查看安装情况:rpm -qa|grep samba 根据系统的安装情况选择下载或者通过光驱安装所缺的rpm包. 我的安装情况 ...
- Nhiberate (一)
严重参考感谢:@wolfy 操作数据库一直都是直接写SQL语句, 接触的ORM框架也不多,新项目要用数据库,数据库访问采用NHibernate. 1. NHibernate 是基于.Net 的针对关系 ...
- jquery例子
jquery <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- iOS,文本输入,键盘相关
1.UIKeyboard键盘相关知识点 2.点击空白区域隐藏键盘(UIKeyboard) 3.键盘(UIKeyboard)挡住输入框处理 4.自定义键盘(UIKeyboard) 5.监听键盘弹出或消失 ...