码迷,mamicode.com
首页 > 其他好文 > 详细

342. Power of Four(One-line)

时间:2016-04-18 13:16:59      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

342. Power of Four

 

 
 
Total Accepted: 707 Total Submissions: 2005 Difficulty: Easy

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?

One_line Code:

return(num&num-1) ==0 &&(num&1431655765);

342. Power of Four(One-line)

标签:

原文地址:http://www.cnblogs.com/Alex0111/p/5403970.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!