mycode

class Solution(object):
def isPowerOfThree(self, n):
"""
:type n: int
:rtype: bool
"""
while n > 2:
if n%3 != 0 :
return False
n = n // 3
print(n)
return n == 1

参考

class Solution(object):
def isPowerOfThree(self, n):
"""
:type n: int
:rtype: bool
"""
if n <= 0:
return False
while n%3 == 0:
n = n/3
return n==1

leetcode-easy-math-326. Power of Three的更多相关文章

  1. &lt;LeetCode OJ&gt; 326. Power of Three

    326. Power of Three Question Total Accepted: 1159 Total Submissions: 3275 Difficulty: Easy 推断给定整数是否是 ...

  2. 【leetcode❤python】326. Power of Three

    #-*- coding: UTF-8 -*- class Solution(object):    def isPowerOfThree(self, n):        if n<=0:    ...

  3. leetcode 326. Power of Three(不用循环或递归)

    leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...

  4. [LeetCode] 231 Power of Two && 326 Power of Three && 342 Power of Four

    这三道题目都是一个意思,就是判断一个数是否为2/3/4的幂,这几道题里面有通用的方法,也有各自的方法,我会分别讨论讨论. 原题地址:231 Power of Two:https://leetcode. ...

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

  6. 2015弱校联盟(1) -A. Easy Math

    A. Easy Math Time Limit: 2000ms Memory Limit: 65536KB Given n integers a1,a2,-,an, check if the sum ...

  7. scu 4436: Easy Math 水题

    4436: Easy Math Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.scu.edu.cn/soj/problem.actio ...

  8. [ACM-ICPC 2018 徐州赛区网络预赛][D. Easy Math]

    题目链接:Easy Math 题目大意:给定\(n(1\leqslant n\leqslant 10^{12}),m(1\leqslant m\leqslant 2*10^{9})\),求\(\sum ...

  9. LeetCode 第 231 题 (Power of Two)

    LeetCode 第 231 题 (Power of Two) Given an integer, write a function to determine if it is a power of ...

  10. 数学 SCU 4436 Easy Math

    题目传送门 /* 数学题:当有一个数开根号后是无理数,则No */ #include <cstdio> #include <algorithm> #include <cs ...

随机推荐

  1. weex animation模块 使用指南

    本节学习目标 掌握内置组件animation的使用 我们在开发应用的时候,常常需要增加一些动画效果,来提高用户体验,经常用到的一些动画效果如下 平移 旋转 缩放 背景颜色改变 组件透明图 weex 提 ...

  2. 第二十一篇 jQuery 学习3 特效效果

    jQuery 学习3   这节课主要是学习jQuery的动态效果. show()和hide()显示与隐藏方法,toggle()方法,fadeIn()谈入,fadeOut()谈出,slideDown() ...

  3. 华为ensp问题:云映射本地网卡,直连路由器可以ping通,pc却不行?

    拓扑图:cloud 云映射本机物理网卡:192.168.56.1     R1可以Ping通,所有Pc都不行,路由表也存在路由信息,不知道什么问题?

  4. spring常用的几个aware bean接口

    BeanNameAware 作用:让Bean获取自己在BeanFactory配置中的名字(根据情况是id或者name). Spring自动调用.并且会在Spring自身完成Bean配置之后,且在调用任 ...

  5. 执行dlsym()函数出现: undefined symbol

    执行dlsym()函数出现: undefined symbol 执行dlsym()函数出现: undefined symbol 当这个问题出现的时候,可以检查产生so文件的cpp文件,看看是否已经用  ...

  6. spring-data-neo4j 4.2.4release文档概要

    Neo4j是一种开源的NoSQL图数据库,将数据以图(把一个个实体当作节点,连接节点的边表示节点间的关系)的形式保存,Neo4j也支持ACID事务管理.关系型数据库数据访问采用的是ORM(对象关系映射 ...

  7. Linux基本命令之Vim

    在vim,vi,gedit编辑器中显示行号:        在命令模式下:set nu 取消行号:set nonu 参照博客:https://www.cnblogs.com/Mr0wang/p/728 ...

  8. Scale-up and Scale-out(转载)

    原地址:http://www.cnblogs.com/spork/archive/2009/12/29/1634766.html 来自原小站,曾经迷糊过的东西,表上来,希望对正在迷糊或即将迷糊的人有帮 ...

  9. Spring Boot整合拦截器

    过滤器和监听器都属于Servlet 的api,还可以使用 Spring 提供的拦截器(HandlerInterceptor)进行改更精细的控制.

  10. mysql之InnoDb引擎与MyISAM引擎对比

    InnoDb引擎 支持ACID的事务,支持事务的四种隔离级别: 支持行级锁及外键约束:因此可以支持写并发: 不存储总行数: 一个InnoDb引擎存储在一个文件空间(共享表空间,表大小不受操作系统控制, ...