/*

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 PowerOfThree {
private static final double EX=10e-15; public static void main(String[] args) {
// TODO Auto-generated method stub
int d=243;
System.out.println(isPowerOfThree(d));
} public static boolean isPowerOfThree(int n) {
if(n==0)
return false;
double res=Math.log(n)/Math.log(3);
System.out.println(res);
return (Math.abs((res-Math.round(res)))<EX); //注意为什么不能用floor和ceil 注意double 其实还可以bigdecimal?
}
}

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] 231 Power of Two && 326 Power of Three && 342 Power of Four

    这三道题目都是一个意思,就是判断一个数是否为2/3/4的幂,这几道题里面有通用的方法,也有各自的方法,我会分别讨论讨论. 原题地址:231 Power of Two:https://leetcode. ...

  4. &lt;LeetCode OJ&gt; 326. Power of Three

    326. Power of Three Question Total Accepted: 1159 Total Submissions: 3275 Difficulty: Easy 推断给定整数是否是 ...

  5. 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 ...

  6. 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 ...

  7. 【一天一道LeetCode】#326. Power of Three

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

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

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

  9. 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 ...

随机推荐

  1. replace() replace_copy()

    int a[] = {1,2,3,3,4}; vector<int> v(a, a+5); vector<int> v2; //replace(v.begin(), v.end ...

  2. 目录操作工具类 CopyDir.java

    package com.util; import java.io.*; /** * 1,建立目的目录. 2,遍历源目录. 3,遍历过程中,创建文件或者文件夹. 原理:其实就是改变了源文件或者目录的目录 ...

  3. junit类找不到的问题解决

    1. Class not found  *******java.lang.ClassNotFoundException: ******* at java.net.URLClassLoader$1.ru ...

  4. 【linux】日志管理

    1.日志文件内容的一般格式 (1)事件发生的日期与时间: (2)发生此事件的主机名: (3)启动此事件的服务名称或函数名称: (4)该信息的实际数据内容. 例如:Mar 14 15:38:00 www ...

  5. jQ的toggle()方法示例

    定义和用法toggle() 方法切换元素的可见状态.如果被选元素可见,则隐藏这些元素,如果被选元素隐藏,则显示这些元素. 语法$(selector).toggle(speed,callback,swi ...

  6. DNS查询指令nslookup

    描述: Nslookup指令是一个查询internet域名服务的程序.Nslookup指令有两个模式:交互式和非交互式. 交互式模式允许用户查询不同种类的主机和域名或在一个域名里输出主机列表,目的是查 ...

  7. 黄聪:Mysql数据库还原备份提示MySQL server has gone away 的解决方法(备份文件数据过大)

    使用mysql做数据库还原的时候,由于有些数据很大,会出现这样的错误:The MySQL Server returned this Error:MySQL Error Nr. MySQL server ...

  8. Apple dev travel

    Objective-C最基础语法之Class定义: http://mobile.51cto.com/iphone-281925.htm  Table View: http://www.appcoda. ...

  9. Unix commands in Mac OS X

    参考:http://www.renfei.org/blog/mac-os-x-terminal-101.html One command line includes 4 parts: Command ...

  10. HDU 1506 Largest Rectangle in a Histogram set+二分

    Largest Rectangle in a Histogram Problem Description: A histogram is a polygon composed of a sequenc ...