LN : leetcode 231 Power of Two

lc 231 Power of Two


231 Power of Two

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

analysation##

Easy problem.

solution

bool isPowerOfTwo(int n) {
  if (n <= 0)
  return false;
  while (n%2 == 0)
  n = n>>1;
  return (n == 1);
}
posted @ 2016-04-21 22:16  三石宝宝  阅读(154)  评论(0编辑  收藏  举报