leetcode 326 Power of Three (python)
原题:
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)的更多相关文章
- leetcode 326. Power of Three(不用循环或递归)
		leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ... 
- 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 ... 
- [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 ... 
- 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 ... 
- 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 ... 
- LeetCode 326 Power of Three(3的幂)(递归、Log函数)
		翻译 给定一个整型数,写一个函数决定它是否是3的幂(翻译可能不太合适-- 跟进: 你能否够不用不论什么循环或递归来完毕. 原文 Given an integer, write a function t ... 
- Leetcode 326 Power of Three 数论
		判断一个数是否是3的n次幂 这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) = 1162261467)的约数 这种方法是我 ... 
- [LeetCode] 326. Power of Three + 342. Power of Four
		这两题我放在一起说是因为思路一模一样,没什么值得研究的.思路都是用对数去判断. /** * @param {number} n * @return {boolean} */ var isPowerOf ... 
- [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: ... 
随机推荐
- django  inspectdb
			使用inspectdb --通过已有数据库表生成 model.pyinspectdb辅助工具检查你的settings文件指向的数据库,决定你表示你的表的Django模型并打印Python模型代码到标 ... 
- C# Oracle.ManagedDataAccess 批量更新表数据
			这是我第一次发表博客.以前经常到博客园查找相关技术和代码,今天在写一段小程序时出现了问题, 但在网上没能找到理想的解决方法.故注册了博客园,想与新手分享(因为本人也不是什么高手). vb.net和C# ... 
- redis  导出查询结果
			查询zset zrevrange mail:object:1258822-1175360:object 0 -1 导出符合条件的redis 到指定目录 echo "keys user:id: ... 
- 如何修改Linux系统的  /etc/ssh/sshd_config 文件   "/etc/ssh/sshd_config" E212: Can't open file for writin
			第一步:我们使用命令行vim /etc/ssh/sshd_config 执行修改,强制保持 :wq! 系统不让我们修改这个文件 "/etc/ssh/sshd_config" ... 
- 使用ng-grid实现可配置的表格
			使用Angularjs在带来方便的同时,也有一些遗憾:很多基于jquery或其它的组件,在angularjs中需要集成一下才能用得流畅.但是一些比较复杂的组件,集成起来的工作量相当大,比如说grid. ... 
- Enable multithreading to use std::thread: Operation not permitted问题解决
			在用g++ 4.8.2编译C++11的线程代码后,运行时遇到了如下报错: terminate called after throwing an instance of 'std::system_err ... 
- JQuery EasyUI dialog弹出框的 close 和 destroy
			开发项目中(使用JQuery EasyUI),根据业务需要重叠弹出多个提示框的情况,会出现如下情况:页面出现两个div模块调用同一个弹出页面,页面的数据接受框元素不能实时存储数据解决方案: 使用$(t ... 
- sqoop从hdfs 中导出数据到mysql
			bin/sqoop export \ --connect "jdbc:mysql://mini1:3306/study?useUnicode=true&characterEncodi ... 
- linux内核开机logo显示调试
			要使内核支持开机logo显示需要配置内核 配置如下: make menuconfig: Device Drivers ---> Graphics support ---> ... 
- TCP会话劫持_转
			前言通常,大家所说的入侵,都是针对一台主机,在获得管理员权限后,就很是得意:其实,真正的入侵是占领整个内部网络.针对内部网络的攻击方法比较多,但比较有效的方法非ARP欺骗.DNS欺骗莫属了.但是,不管 ... 
