原题:

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. jBoss无法通过IP地址访问,只能用localhost\127.0.0.1访问

    http://feng88724.iteye.com/blog/263211 JBOSS版本:4.2.2GA 症状:服务器无法通过IP地址去访问,只能用127.0.0.1或者localhost来访问. ...

  2. PHP拿到别人项目如何修改为自己

    以下为借助google翻译的,个人润色了一下,官方版里面感觉有很多问题,我这里有我个人修改大部分问题的版本,包括翻译完善,有需要的可以联系我:qyj8411@163.com 1. 在您网站的根目录创建 ...

  3. timedelta

    from datetime import datetime start="09:35:23" end="10:23:00" start_dt = datetim ...

  4. MQTT Client软件-MQTTBox

    最近发现了一个连接mqtt broker的软件:MQTTBox.GitHub地址:https://github.com/workswithweb/MQTTBox 官网网站的介绍为:使用MQTTBox增 ...

  5. sklearn基本回归方法

    https://blog.csdn.net/u010900574/article/details/52666291 博主总结和很好,方法很实用. python一些依赖库: https://www.lf ...

  6. HTTPSConnectionPool(host='xxxxx', port=443): Max retries exceeded with url:xxxxxxxx (Caused by NewConnectionError('<urllib3.connect,Max retries exceeded with ,(Caused by NewConnectionError

    HTTPSConnectionPool(host='f6ws-sha8re-o88k.s3.ama66zaws.com', port=443): Max retries exceeded with u ...

  7. SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled)

    SElinux共有3中状态.1.selinux的配置文件:/etc/selinux/config# This file controls the state of SELinux on the sys ...

  8. JSON的String字符串与Java的List列表对象的相互转换

    1.JSON的String字符串与Java的List列表对象的相互转换 在前端: 1.如果json是List对象转换的,可以直接遍历json,读取数据. 2.如果是需要把前端的List对象转换为jso ...

  9. AxureRP_for_chorme的安装和使用方法

    1.下载AxureRP_for_chorme_version.crx 2.打开Chrome,右上角菜单图标->更多->扩展程序 3.将crx文件拖入,安装 4.选中AxureRP的“已启用 ...

  10. STL源代码剖析——STL算法stl_algo.h

    前言 在前面的博文中剖析了STL的数值算法.基本算法和set集合算法.本文剖析STL其它的算法,比如排序算法.合并算法.查找算法等等.在剖析的时候.会针对函数给出一些样例说明函数的使用.源代码出自SG ...