2019独角兽企业重金招聘Python工程师标准>>>

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?

Credits:
Special thanks to @dietpepsi for adding this problem and creating all test cases.

解答:

func isPowerOfThree(n int) bool {
    if n == 0 {
        return false
    }
    c := math.Log10(float64(n)) / math.Log10(3)
    d := float64(int64(c))
    return (c - d) < 0.0000000001
}

转载于:https://my.oschina.net/ifraincoat/blog/1069049

LeetCode:326. Power of Three相关推荐

  1. LeetCode 326. Power of Three

    题目: Given an integer, write a function to determine if it is a power of three. Follow up: Could you ...

  2. [leetcode]326. Power of Three(c语言)

    题目 Given an integer, write a function to determine if it is a power of three. Follow up: Could you d ...

  3. 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 i ...

  4. leetcode 326. 3的幂(Power of Three)

    目录 题目描述: 示例 1: 示例 2: 示例 3: 示例 4: 进阶: 解法: 题目描述: 给定一个整数,写一个函数来判断它是否是 3 的幂次方. 示例 1: 输入: 27输出: true 示例 2 ...

  5. [LeetCode][JavaScript]Power of Three

    Power of Three Given an integer, write a function to determine if it is a power of three. Follow up: ...

  6. [leetcode] 342. Power of Four

    题目 Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example: ...

  7. leetcode 342. Power of Four

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Gi ...

  8. leetcode 231. Power of Two

    Given an integer, write a function to determine if it is a power of two. class Solution(object):def ...

  9. LeetCode - 231. Power of Two

    Given an integer, write a function to determine if it is a power of two. Example 1: Input: 16 Output ...

最新文章

  1. 900 多道 LeetCode 题解,这个 GitHub 项目值得 Star!
  2. iOS多线程编程之多线程简单介绍(转载)
  3. JavaScript进阶系列01,函数的声明,函数参数,函数闭包
  4. Cordova for iOS[ PhoneGap]
  5. Redis根据是否存在设置值
  6. linux中sh+$0,浅谈linux中shell变量$#,$@,$0,$1,$2的含义解释
  7. 可视化日历(Java实现)
  8. bzoj 2296: 【POJ Challenge】随机种子
  9. opencv 二值化_Python-OpenCV获取图像轮廓的图像处理方法
  10. 学术不端!211大学一名博士被撤销学位!
  11. 【C#夯实】我与接口二三事:IEnumerable、IQueryable 与 LINQ
  12. 广州爱立信java笔试题_爱立信笔试经历
  13. 基于sklearn分析特征工程(特征预处理、特征选择、降维)
  14. iOS开发之画图板(贝塞尔曲线)
  15. HTML_BOM-01
  16. 人工智能成功与冠状病毒抗争,但个人隐私令人担忧
  17. 自动识别并汇总发票信息的智能机器人来啦!
  18. android中bmob云存储,Android中的Bmob移动后端云服务器功能
  19. 虚拟机怎么安装软件 Mac虚拟机怎么安装软件
  20. K8S学习之storageclass

热门文章

  1. 用于视力恢复的脑机接口综述(一)(修改)
  2. Unity中实现Hololens的三维空间映射Spatial mapping
  3. 中国首款L4级Robovan发布!文远知行商用落地两条腿走路
  4. 数学好=编程能力强?MIT新发现:二者激活大脑区域并不同
  5. 我是清华新任教授张亚勤,现在只想做成这一件事
  6. 在PyTorch上用Keras,分布式训练开箱即用,告别没完没了的Debug
  7. ssh整合之六管理我们的配置文件
  8. RHEL 5基础篇—了解系统的引导过程
  9. Linux下添加新硬盘,分区及挂载
  10. 用GDB调试程序(一)