原题:

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. 通过设置标签class值控制标签的显示与隐藏

    需求背景如下: 原项目居民.单位.计量三模块共用一个jsp文件,显示的页面也顺理成章的统一了,幸亏没有调用同一个js,在此基础上要求居民和单位计量的分离,即居民的显示居民的相关信息,单位和计量的显示相 ...

  2. SSH限制ip登陆

    linux限制IP访问ssh   在/etc/hosts.allow输入   (其中192.168.10.88是你要允许登陆ssh的ip,或者是一个网段192.168.10.0/24)   sshd: ...

  3. 安装应用程序 报“ 997 重叠 I/O 操作在进行中”错解决办法

    解决办法: 原因: Per Microsoft's blog, patch KB2918614 appears to have caused installation issues 按照微软的博客,补 ...

  4. Android_JarZip压缩和解压文件

        本文资料来自<android开发权威指南> AndroidSDK中提供了java.util.jar和java.util.zip包中的若干类和接口来完成. 压缩文件基本步骤: 1.创 ...

  5. php处理XML数据

    把XML转换成对象直接调用里面的属性 <?php$note=<<<XML<note><to>Tove</to><from>Jan ...

  6. django学习笔记【002】创建第一个django app

    2.3.3 1.创建一个名叫polls的app python3. manage.py startapp polls tree mysite/ mysite/ ├── db.sqlite3 ├── ma ...

  7. R内存扩展 win7内存扩展

    安装包 imdiskinst 文件 램디스크 사용http://www.ltr-data.se/ http://cruciancar.blog.me/150101634586 --TEMP 변수 TE ...

  8. 又开一坑,运动图形MoGraph for Unity

    Fragment+random: Vertex+random, Vertex+plain Vertex+Sound Plexus like 写了个大概,暂时没这方面需求先放这边了. C4D原版片段和克 ...

  9. jQuery 语法(一)

    通过 jQuery,您可以选取(查询,query) HTML 元素,并对它们执行“操作”(actions). jQuery 语法实例 $(this).hide() 演示 jQuery hide() 函 ...

  10. numpy.ravel()/numpy.flatten()/numpy.squeeze()

    numpy.ravel(a, order='C') Return a flattened array numpy.chararray.flatten(order='C') Return a copy ...