Leecode刷题之旅-C语言/python-342 4的幂
这里不列举普通的方法了。
发现一个好帖:
学习一下:
https://blog.csdn.net/butterfly5211314/article/details/86099993
----------------------------------------------------------------------------------
pyhton的:
#
# @lc app=leetcode.cn id=342 lang=python3
#
# [342] 4的幂
#
# https://leetcode-cn.com/problems/power-of-four/description/
#
# algorithms
# Easy (44.37%)
# Total Accepted: 6.1K
# Total Submissions: 13.8K
# Testcase Example: '16'
#
# 给定一个整数 (32 位有符号整数),请编写一个函数来判断它是否是 4 的幂次方。
#
# 示例 1:
#
# 输入: 16
# 输出: true
#
#
# 示例 2:
#
# 输入: 5
# 输出: false
#
# 进阶:
# 你能不使用循环或者递归来完成本题吗?
#
#
class Solution:
def isPowerOfFour(self, num: int) -> bool:
if num<=0:
return False
return True if pow(4,int(math.log(num,4)))==num else False #使用log函数实现,记住加int
Leecode刷题之旅-C语言/python-342 4的幂的更多相关文章
- Leecode刷题之旅-C语言/python-1.两数之和
开学后忙的焦头烂额(懒得很),正式开始刷leecode的题目了. 想了想c语言是最最基础的语言,虽然有很多其他语言很简单,有更多的函数可以用,但c语言能煅炼下自己的思考能力.python则是最流行的语 ...
- Leecode刷题之旅-C语言/python-387 字符串中的第一个唯一字符
/* * @lc app=leetcode.cn id=387 lang=c * * [387] 字符串中的第一个唯一字符 * * https://leetcode-cn.com/problems/f ...
- Leecode刷题之旅-C语言/python-28.实现strstr()
/* * @lc app=leetcode.cn id=28 lang=c * * [28] 实现strStr() * * https://leetcode-cn.com/problems/imple ...
- Leecode刷题之旅-C语言/python-7.整数反转
/* * @lc app=leetcode.cn id=7 lang=c * * [7] 整数反转 * * https://leetcode-cn.com/problems/reverse-integ ...
- Leecode刷题之旅-C语言/python-434 字符串中的单词数
/* * @lc app=leetcode.cn id=434 lang=c * * [434] 字符串中的单词数 * * https://leetcode-cn.com/problems/numbe ...
- Leecode刷题之旅-C语言/python-326 3的幂
/* * @lc app=leetcode.cn id=326 lang=c * * [326] 3的幂 * * https://leetcode-cn.com/problems/power-of-t ...
- Leecode刷题之旅-C语言/python-263丑数
/* * @lc app=leetcode.cn id=263 lang=c * * [263] 丑数 * * https://leetcode-cn.com/problems/ugly-number ...
- Leecode刷题之旅-C语言/python-383赎金信
/* * @lc app=leetcode.cn id=383 lang=c * * [383] 赎金信 * * https://leetcode-cn.com/problems/ransom-not ...
- Leecode刷题之旅-C语言/python-349两整数之和
/* * @lc app=leetcode.cn id=371 lang=c * * [371] 两整数之和 * * https://leetcode-cn.com/problems/sum-of-t ...
- Leecode刷题之旅-C语言/python-349两个数组的交集
/* * @lc app=leetcode.cn id=349 lang=c * * [349] 两个数组的交集 * * https://leetcode-cn.com/problems/inters ...
随机推荐
- Python学习---DjangoForm的总结大全
DjangoForm基础知识总结 1.Form是什么东西? 用于验证用户请求数据合法性的一个组件 2. Django的Form的实现步骤: a. 创建一个验证用户请求的模板 from django i ...
- Mysql学习---使用Python执行存储过程
使用Python执行存储过程 使用Python执行存储过程[2部分]: 1.执行存储过程,获取存储过程的结果集 2.将返回值设置给了 @_存储过程名_序号 = #!/usr/bin/env pyt ...
- 最优化 KKT条件
对于约束优化问题: 拉格朗日公式: 其KKT条件为: 求解 x.α.β 其中β*g(x)为互补松弛条件 KKT条件是使一组解成为最优解的必要条件,当原问题是凸问题的时候,KKT条件也是充分条件.
- August 17th 2017 Week 33rd Thursday
Fate is responsible for shuffling, but the game of cards is our own! 命运负责洗牌,但是玩牌的是我们自己! Today, I upd ...
- January 07 2017 Week 1st Saturday
Procrastination is the thief of time. 拖延乃是光阴之窃贼. My parents always tell me that things ought to be d ...
- requirejs 多页面,多js 打包代码,requirejs多对多打包
这段代码来自 http://stackoverflow.com/questions/20583812/grunt-requirejs-optimizer-for-a-multi-app-project ...
- mongd配置文件解释
mongd配置文件解释 系统日志配置 systemLog: verbosity: <int> quiet: <boolean> traceAllExceptions: < ...
- 使用泛型和内部静态类实现栈(FILO,先进后出)
package tuple; /** * 泛型实现的栈,FILO * @author Youjie * * @param <T> */ public class LinkedStack&l ...
- UVa 10288 - Coupons(数学期望 + 递推)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 1、Android-活动(上)
1.1.活动是什么 活动(Activity)是最容易吸引用户的地方,他是一种可以包含用户界面的组件 主要用于和用户进行交互 一个用户可以包含零个或多个活动,不包含活动的程序少见 1.2.活动的基本用法 ...