## 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?

Credits:
Special thanks to @yukuairoy for adding this problem and creating all test cases.

Hint

Code

``````public class Solution {
public boolean isPowerOfFour(int num) {
boolean result = false;

if (num > 0) {
if (((num & (num - 1)) == 0) && ((num - 1) % 3 == 0)) {
result = true;
}
}

return result;
}
}``````

### 初雪之音

Leetcode 342. Power of Four

SnailTyan
2018/09/04
0
0

2018/03/30
0
0
LeetCode - 326, 342, 231 Power of Three, Four, and Two

1. 问题 231. Power of Two: 判断一个整数是否是2的n次方，其中n是非负整数 342. Power of Four: 判断一个整数是否是4的n次方，其中n是非负整数 326. Power of Three: 判断一个整数是否是3的...

rgvb178
2017/08/30
0
0
haproxy不能重启 ，牛牛们快来帮帮小弟 异常信息如下：

[ALERT] 342/182315 (5022) : parsing [/etc/haproxy/haproxy.cfg:1]: unknown keyword 'Global' out of section. [ALERT] 342/182315 (5022) : parsing [/etc/haproxy/haproxy.cfg:2]: unkn......

larry_xiang
2014/12/09
2.2K
6
Spring security小问题，求助AccessDeniedException异常抛出

Spring security问题 功能是实现了，跳转到了403页面 但是AccessDeniedException异常抛出在控制台 报错 （MyAccessDecisionManager.java:51） 50 //没有权限 51 throw new AccessDeniedExcep...

2016/04/15
503
0

2
0
Redis协议是什么样的

4
0

linuxCool

4
0

morpheusWB

3
0

Linux就该这么学

6
0