LeetCode 342
Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
Example:
Given num = 16, return true. Given num = 5, return false.
Follow up: Could you solve it without loops/recursion?
/*************************************************************************
> File Name: LeetCode342.c
> Author: Juntaran
> Mail: Jacinthmail@gmail.com
> Created Time: 2016年05月10日 星期二 02时50分00秒
************************************************************************/ /************************************************************************* Power of Four Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:
Given num = 16, return true. Given num = 5, return false. Follow up: Could you solve it without loops/recursion? ************************************************************************/ #include "stdio.h" int isPowerOfFour(int num) {
double tmp = log10(num)/log10();
return tmp == (int)tmp ? : ;
} int main()
{
int n = ;
int ret = isPowerOfFour(n);
printf("%d\n",ret); n = ;
ret = isPowerOfFour(n);
printf("%d\n",ret); return ;
}
LeetCode 342的更多相关文章
- LeetCode 342. Power of Four (4的次方)
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...
- [LeetCode] 342. Power of Four 4的次方数
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...
- Java实现 LeetCode 342 4的幂
342. 4的幂 给定一个整数 (32 位有符号整数),请编写一个函数来判断它是否是 4 的幂次方. 示例 1: 输入: 16 输出: true 示例 2: 输入: 5 输出: false 进阶: 你 ...
- LeetCode 342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...
- Leetcode 342 Power of Four 数论
题意:判断一个数是不是4的幂数,和Power of two类似. 先判断num是否大于0,再判断num是否能开根号,最后判断num开根号后的数是否是2^15的约数. 提示:4的幂数开根号就是2的幂数. ...
- Python [Leetcode 342]Power of Four
题目描述: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Examp ...
- [LeetCode] 342. 4的幂 ☆(是否4 的幂)
描述 给定一个整数 (32 位有符号整数),请编写一个函数来判断它是否是 4 的幂次方. 示例 1: 输入: 16输出: true示例 2: 输入: 5输出: false 进阶:你能不使用循环或者递归 ...
- leetcode 342. 4的幂(python)
1. 题目描述 给定一个整数 (32 位有符号整数),请编写一个函数来判断它是否是 4 的幂次方. 示例 1: 输入: 16输出: true示例 2: 输入: 5输出: false 2. 思路 参考: ...
- [LeetCode] 342. Power of Four(位操作)
传送门 Description Given an integer (signed 32 bits), write a function to check whether it is a power o ...
随机推荐
- jQuery-validate error messages in Twitter ...
http://www.jefclaes.be/2012/11/jquery-validate-error-messages-in.html something satisfactory. In thi ...
- C++问题-无法打开某个自定义源文件
问题经过:需要做一个工具,是在某个产品的基础上做的,所以要来了同事的代码.用VS打开后,提示如下问题.1>c1xx : fatal error C1083: 无法打开源文件:“..\..\GUX ...
- C++问题-无法打开包括文件:“GLES2/gl2.h”
资料来源:http://blog.csdn.net/weizehua/article/details/12623719http://tieba.baidu.com/p/2747715029 问题经过: ...
- HDU 5665 Lucky (水题)
Lucky 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/G Description Chaos August likes to ...
- UVA 10054 The Necklace(欧拉回路,打印路径)
题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- Spring @RequestHeader用法
Spring MVC提供了 @RequestHeader注解,能够将请求头中的变量值映射到控制器的参数中.下面是一个简单的例子: import org.springframework.stereoty ...
- MFC中常用的内容
在程序中更改静态文本内容. GetDlgItem(IDC_STATIC)->SetWindowText("欢迎"); 不用UpdateData(false); 如果提示con ...
- SQL Select的执行顺序
1.FROM 2.ON 3.JOIN 4.WHERE 5.GROUP BY 6.WITH CUBE or WITH ROLLUP 7.HAVING 8.SELECT 9.DISTINCT 10.ORD ...
- Windows下sqlmap的使用_01
环境:win8.1 64位 一.下载 首先,需下载SqlMap以及适用于Windows系统的Python.下载地址如下: 1.1.SqlMap下载地址:https://github.com/ ...
- JS Math 类库介绍
下面介绍下随机生成数的常用几个API JS 随机数生成 : 在JavaScript , 提供了生成随机数的API, Math.random() 1.Math.random() : 随机生成小数 . 生 ...