/*

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. html之texteara

    定义多行的文本输入控件,所有浏览器都支持,可容纳无限的文本,等宽的字体. 用css的height和width来设置其框框的大小是个很好的办法,其中的文本换行符为%OD/%OA(回车换行) html5中 ...

  2. 【性能诊断】七、并发场景的性能分析(windbg案例,线程阻塞)

    简单整理一个测试Demo,抓取dump并验证,步骤如下: Symbol File Path:SRV*C:\Symbols*http://msdl.microsoft.com/download/symb ...

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

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

  4. java生成随机字符串uuid

    GUID是一个128位长的数字,一般用16进制表示.算法的核心思想是结合机器的网卡.当地时间.一个随即数来生成GUID.从理论上讲,如果一台机器每秒产生10000000个GUID,则可以保证(概率意义 ...

  5. Andaroid L新特性

    1.Material Design”(材料设计)的全新设计理念,和Holo相比,Material Design更加色彩丰富,不像Holo那样灰暗 2.1)卡片风格(锁屏界面) 2)环动式设计  And ...

  6. html简介

    什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Text Markup Language) HTML 不是一种编程语言,而是一种标记语言 (ma ...

  7. android学习笔记九——RatingBar

    RatingBar==>星级评分条 RatingBar和SeekBar十分相似,它们甚至有相同的父类:AbsSeekBar.两者都允许用户通过拖动来改变进度: 两者最大的区别在于RatingBa ...

  8. HTML网页调用本地QQ

    打开聊天窗口代码: tencent://message/?uin=QQ号码&Site=有事Q我&Menu=yes 使用方法: <a href="tencent://me ...

  9. 【SQL Server】系统学习之一:表表达式

    本节讨论的相关内容包括:视图.派生表.CTE.内联表值函数 场景:如果要查询一组数据(例如聚合数据,也就是几个表聚合在一起的数据),这些数据并未在数据库中以表的形式存在. 1.视图:通常用来分解大型的 ...

  10. 黄聪:深入理解PHP Opcode缓存原理

    什么是opcode缓存? 当解释器完成对脚本代码的分析后,便将它们生成可以直接运行的中间代码,也称为操作码(Operate Code,opcode).Opcode cache的目地是避免重复编译,减少 ...