这里不列举普通的方法了。
发现一个好帖:
学习一下:
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