zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Unit of Work
    OAuth做webapi认证
    Js数组
    UWP开发的一些思考
    表格行拖拽
    委托
    Git协作流程(转)
    全自动Web后门扫描(转)
    Gradle 2.0用户手册——总览(译)(转)
    面向对象之两大要领 (转)
  • 原文地址:https://www.cnblogs.com/lixiaoyao123/p/10564006.html
Copyright © 2011-2022 走看看