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 ...
随机推荐
- HDU 2063 过山车(二分匹配入门)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 二分匹配最大匹配数简单题,匈牙利算法.学习二分匹配传送门:http://blog.csdn.ne ...
- rqnoj-390-地震了!-动态规划
一步步的往前走,判断当前状态与上一个状态的关闭. 注意,题目输入的楼层的速度是从小到大,而实际运用的楼层顺序是从大到小.. #include<stdio.h> #include<al ...
- http协议详细介绍
HTTP协议/IIS 原理及ASP.NET运行机制浅析[图解] 转自:http://www.cnblogs.com/wenthink/archive/2013/05/06/HTTP_IIS_ASPNE ...
- 神经网络学习-问题(二)-scipy未正确安装报DLL找不到的问题
问题如下: E:\project\DL\python\keras>python keras_sample.pyUsing Theano backend.Traceback (most recen ...
- maven for eclipse在线安装
在线安装 地址变了下面的: http://download.eclipse.org/technology/m2e/releases Eclipse Indigo安装Maven插件Maven ...
- PostgreSQL的 initdb 源代码分析之十五
继续分析: if (pwprompt || pwfilename) get_set_pwd(); 由于我启动initdb的时候,没有设置口令相关的选项,故此略过. 接下来: setup_depend( ...
- IOS Note - Outlet(插座) & Action(动作)
OutletActionViewController.h #import <UIKit/UIKit.h> @interface OutletActionViewController : U ...
- TV
https://github.com/Xs4allWebTV/androidhttps://github.com/mode89/video-feedhttp://www.javaapk.com/sou ...
- [Angular 2] Create Shareable Angular 2 Components
Components that you use across multiple applications need to follow a module pattern that keeps them ...
- [AngularJS] Lazy loading Angular modules with ocLazyLoad
With the ocLazyLoad you can load AngularJS modules on demand. This is very handy for runtime loading ...