zoukankan      html  css  js  c++  java
  • LeetCode 231

    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
    ",ret);
    28     
    29     n = 16;
    30     ret = isPowerOfTwo(n);
    31     printf("%d
    ",ret);
    32     
    33     return 0;
    34 }
  • 相关阅读:
    进程虚拟内存
    非连续内存区缺页异常处理
    请求调页和写时复制
    标签对齐(补充)
    shell数学表达式
    缺页异常的处理
    不错的书籍
    imag database2
    image database
    Apache down了?
  • 原文地址:https://www.cnblogs.com/Juntaran/p/5479097.html
Copyright © 2011-2022 走看看