这里不列举普通的方法了。

发现一个好帖:

学习一下:

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的幂的更多相关文章

  1. Leecode刷题之旅-C语言/python-1.两数之和

    开学后忙的焦头烂额(懒得很),正式开始刷leecode的题目了. 想了想c语言是最最基础的语言,虽然有很多其他语言很简单,有更多的函数可以用,但c语言能煅炼下自己的思考能力.python则是最流行的语 ...

  2. Leecode刷题之旅-C语言/python-387 字符串中的第一个唯一字符

    /* * @lc app=leetcode.cn id=387 lang=c * * [387] 字符串中的第一个唯一字符 * * https://leetcode-cn.com/problems/f ...

  3. Leecode刷题之旅-C语言/python-28.实现strstr()

    /* * @lc app=leetcode.cn id=28 lang=c * * [28] 实现strStr() * * https://leetcode-cn.com/problems/imple ...

  4. Leecode刷题之旅-C语言/python-7.整数反转

    /* * @lc app=leetcode.cn id=7 lang=c * * [7] 整数反转 * * https://leetcode-cn.com/problems/reverse-integ ...

  5. Leecode刷题之旅-C语言/python-434 字符串中的单词数

    /* * @lc app=leetcode.cn id=434 lang=c * * [434] 字符串中的单词数 * * https://leetcode-cn.com/problems/numbe ...

  6. Leecode刷题之旅-C语言/python-326 3的幂

    /* * @lc app=leetcode.cn id=326 lang=c * * [326] 3的幂 * * https://leetcode-cn.com/problems/power-of-t ...

  7. Leecode刷题之旅-C语言/python-263丑数

    /* * @lc app=leetcode.cn id=263 lang=c * * [263] 丑数 * * https://leetcode-cn.com/problems/ugly-number ...

  8. Leecode刷题之旅-C语言/python-383赎金信

    /* * @lc app=leetcode.cn id=383 lang=c * * [383] 赎金信 * * https://leetcode-cn.com/problems/ransom-not ...

  9. Leecode刷题之旅-C语言/python-349两整数之和

    /* * @lc app=leetcode.cn id=371 lang=c * * [371] 两整数之和 * * https://leetcode-cn.com/problems/sum-of-t ...

  10. Leecode刷题之旅-C语言/python-349两个数组的交集

    /* * @lc app=leetcode.cn id=349 lang=c * * [349] 两个数组的交集 * * https://leetcode-cn.com/problems/inters ...

随机推荐

  1. PG数据库空间大小及数据库对象占用空间大小

    select pg_size_pretty(pg_database_size('lrisk')); --查询数据库剩余空间 select pg_database.datname,pg_size_pre ...

  2. Python学习---列表/元组/字典/字符串/set集合/深浅拷贝1207【all】

    1.列表 2.元组 3.字典 4.字符串 5.set集合 6.深浅拷贝

  3. Java实例---俄罗斯方块

    代码分析 定义格子 package com.ftl.tetris; /** * 定义格子 */ import java.awt.image.BufferedImage; public class Ce ...

  4. IPv4地址结构体sockaddr_in详解

    sockaddr_in结构体定义 struct sockaddr_in { sa_family_t sin_family; //地址族(Address Family) uint16_t sin_por ...

  5. August 23rd 2017 Week 34th Wednesday

    Do not pray for easy lives. Pray to be stronger men. 不要祈祷舒适的生活,而是祈祷自己能变得更强大. It seems this quotation ...

  6. SuperSocket 介绍

    一.总体介绍 SuperSocket 是一个轻量级的可扩展的 Socket 开发框架,由江振宇先生开发. 官方网站:http://www.supersocket.net/ SuperSocket具有如 ...

  7. Linux的图形模式和文本模式以及单用户模式切换

    1.默认开机进入文本模式 如果想让开机自动进纯文本模式, 修改/etc/inittab 找到其中的 id:5:initdefault: 这行指示启动时的运行级是5,也就是图形模式 改成3就是文本模式了 ...

  8. Java虚拟机6:垃圾收集(GC)-1(内存溢出和内存泄漏的区别)

    1.前言 在进行垃圾收集之前需要普及几个比较重要的概念. 2.内存溢出和内存泄露的概念和区别: (1):内存溢出(out of memory):是指程序在申请内存时,没有足够的内存空间可以分配,系统不 ...

  9. python 中的pipe

    from multiprocessing import Process,Queue,Pipe import os def f(q): # q.send([42,None,'hello']) print ...

  10. weblogic之CVE-2016-3510反序列化分析

    将反序列化的对象封装进了weblogic.corba.utils.MarshalledObject,然后再对MarshalledObject进行序列化,生成payload字节码.由于Marshalle ...