leetcode-easy-math-326. Power of Three
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的更多相关文章
- <LeetCode OJ> 326. Power of Three
326. Power of Three Question Total Accepted: 1159 Total Submissions: 3275 Difficulty: Easy 推断给定整数是否是 ...
- 【leetcode❤python】326. Power of Three
#-*- coding: UTF-8 -*- class Solution(object): def isPowerOfThree(self, n): if n<=0: ...
- leetcode 326. Power of Three(不用循环或递归)
leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...
- [LeetCode] 231 Power of Two && 326 Power of Three && 342 Power of Four
这三道题目都是一个意思,就是判断一个数是否为2/3/4的幂,这几道题里面有通用的方法,也有各自的方法,我会分别讨论讨论. 原题地址:231 Power of Two:https://leetcode. ...
- 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 ...
- 2015弱校联盟(1) -A. Easy Math
A. Easy Math Time Limit: 2000ms Memory Limit: 65536KB Given n integers a1,a2,-,an, check if the sum ...
- scu 4436: Easy Math 水题
4436: Easy Math Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.scu.edu.cn/soj/problem.actio ...
- [ACM-ICPC 2018 徐州赛区网络预赛][D. Easy Math]
题目链接:Easy Math 题目大意:给定\(n(1\leqslant n\leqslant 10^{12}),m(1\leqslant m\leqslant 2*10^{9})\),求\(\sum ...
- LeetCode 第 231 题 (Power of Two)
LeetCode 第 231 题 (Power of Two) Given an integer, write a function to determine if it is a power of ...
- 数学 SCU 4436 Easy Math
题目传送门 /* 数学题:当有一个数开根号后是无理数,则No */ #include <cstdio> #include <algorithm> #include <cs ...
随机推荐
- Django框架——进阶之AJAX
<script>$("#b1").on("click", function () { // 点击 id是b1的按钮要做的事儿 var i1 = $( ...
- LLVM4.0与3.5编译phase对比
说是LLVM4.0和3.5的对比,其实是Clang的4和3.5的对比.在调试Clang编译源码的过程中,发现-S选项在4.0和3.5中的处理不一样,后来使用命令验证了这个事情 jourluohua@j ...
- javaee 自定义标签实战
用过javaee标准标签库的里的标签应该都知道,标签的存在使得页面上的jsp脚本大大减少,甚至说没有了,大大提高了工作效率,使得页面的整洁性也有了很大的提高.下面我们就 模仿核心标签库中choose标 ...
- Maven配置和使用
Eclipse下的Maven开发环境搭建. 现在要用到Eclipse开发Maven的项目,需要配置Maven,简单整理下配置方法. 1.下载Maven安装包,http://maven.apache.o ...
- Hive 函数(六)
Hive函数 Hive中提供了非常丰富的运算符和内置函数支撑,具体操作如下: 1.内置运算符 1.1关系运算符 运算符 类型 说明 A = B 所有原始类型 如果A与B相等,返回TRUE,否则返回 ...
- Oracle批量导出表数据到CSV文件
需求:把oracle数据库中符合条件的n多表,导出成csv文本文件,并以表名.csv为文件名存放. 实现:通过存储过程中utl_file函数来实现.导出的csv文件放入提前创建好的directory中 ...
- Elasticsearch改动
随着Elasticsearch的版本升级,Elasticsearch的一些特性也在改变,下面是一些需要注意的地方 v6.x 版本之前 : 一个index下面是可以创建多个type v6.x 版本 : ...
- CSS3的多列属性
CSS3 可以将文本内容设计成像报纸一样的多列布局 ㈠CSS3 多列属性 ㈡column-count 属性 ⑴语法:column-count: number|auto; ⑵值: ㈢c ...
- 通用DES加密解密方法
/// <summary> /// DES加密方法 /// </summary> /// <param name="strPlain">明文&l ...
- QT5 Even 事件
事件的引入: 实现功能: 1.点击button 文本框两字改变成button被按下;很简单的在button上转到槽对lineEdit->setTest()设置即可; void myWidget: ...