原题:

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?

这个题目本身没有任何难度,也是easy等级,但是题目要求不能使用循环和迭代,解法如下:

import math
class Solution(object):
def isPowerOfThree(self, n):
"""
:type n: int
:rtype: bool
"""
return False if n <= 0 else n == pow(3, round(math.log(n, 3)))

leetcode 326 Power of Three (python)的更多相关文章

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

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

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

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

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

  7. Leetcode 326 Power of Three 数论

    判断一个数是否是3的n次幂 这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) =  1162261467)的约数 这种方法是我 ...

  8. [LeetCode] 326. Power of Three + 342. Power of Four

    这两题我放在一起说是因为思路一模一样,没什么值得研究的.思路都是用对数去判断. /** * @param {number} n * @return {boolean} */ var isPowerOf ...

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

随机推荐

  1. Android自己定义之流式布局

    流式布局,优点就是父类布局能够自己主动的推断子孩子是不是须要换行,什么时候须要换行,能够做到网页版的标签的效果. 今天就是简单的做了自己定义的流式布局. 详细效果: 原理: 事实上非常easy,Mea ...

  2. 【PHP】组合条件搜索SQL

    前端html多个搜索条件组合 后台一个sql语句,很方便和简洁:仅提供思路. 也可以配合着进行分页操作,非常赞~

  3. 【前端】CSS

    CSS介绍 CSS(Cascading Style Sheet,层叠样式表)定义如何显示HTML元素.l 当浏览器读到一个样式表,它就会按照这个样式表来对文档进行格式化(渲染). CSS语法 CSS实 ...

  4. 关于spring中<context:component-scan base-package="" />写法

    1.通配符形式<context:component-scan base-package="com.*" /> 2.全路径 <context:component-s ...

  5. 在需要隐藏navigationController控制器

    - (void)viewWillAppear:(BOOL)animated {    [super viewWillAppear:animated]; [self.navigationControll ...

  6. 电子商务(电销)平台中订单模块(Order)数据库设计明细(转载)

    电子商务(电销)平台中订单模块(Order)数据库设计明细 以下是自己在电子商务系统设计中的订单模块的数据库设计经验总结,而今发表出来一起分享,如有不当,欢迎跟帖讨论~ 订单表 (order)|-- ...

  7. centos7下安装openvpn,访问内网服务器 (三)证书取消授权

    1.创建临时证书 使用easy-rsa创建额外的证书: [root@origalom openvpn]# cd /usr/share/easy-rsa/2.0/ [root@origalom 2.0] ...

  8. 从【MySQL server has gone away】说起

    本文目的 这几天开发了一个PHP CLI程序,用于后台定时调度执行一些任务.此脚本采用了PHP的多进程(pcntl_fork),共享内存和信号量进行IPC和同步.目的是将串行的任 务并行执行,缩短执行 ...

  9. 编程算法 - 高速排序算法 代码(C)

    高速排序算法 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 经典的高速排序算法, 作为一个编程者, 不论什么时候都要完整的手写. 代码: /* * m ...

  10. Linux定时备份数据到百度云盘

    导读:如今的百度云盘免费容量都是2T了,即使把电脑上所有的东东都放上去,也还有大把的剩余空间.对于站长来说,是完全可以充分利用这些硬盘空间的,现在我们就用百度云盘来备份Linux服务器上的数据. 一直 ...