首页 > 其他 > 详细

LeetCode 231

时间:2016-05-10 20:28:52      阅读:171      评论:0      收藏:0      [点我收藏+]

Power of Two

Given an integer, write a function to determine if it is a power of two.

 

 1 /*************************************************************************
 2     > File Name: LeetCode231.c
 3     > Author: Juntaran    
 4     > Mail: Jacinthmail@gmail.com
 5     > Created Time: 2016年05月10日 星期二 02时55分46秒
 6  ************************************************************************/
 7 
 8 /*************************************************************************
 9     
10     Power of Two
11     
12     Given an integer, write a function to determine if it is a power of two.
13 
14  ************************************************************************/
15 
16 #include "stdio.h"
17 
18 int isPowerOfTwo(int n) {
19     int temp = (n>0 && !(n&(n-1)));
20     return temp;
21 }
22 
23 int main()
24 {
25     int n = 9;
26     int ret = isPowerOfTwo(n);
27     printf("%d\n",ret);
28     
29     n = 16;
30     ret = isPowerOfTwo(n);
31     printf("%d\n",ret);
32     
33     return 0;
34 }

 

LeetCode 231

原文:http://www.cnblogs.com/Juntaran/p/5479097.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!