231. Power of Two

题目:

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

链接: http://leetcode.com/problems/power-of-two/

2/28/2017

看别人的。看来要注意各种比特运算。

1 public class Solution {
2     public boolean isPowerOfTwo(int n) {
3         if (n <= 0) return false;
4     return (n & (n - 1)) == 0;
5     }
6 }

 

posted @ 2017-03-01 04:36  panini  阅读(92)  评论(0编辑  收藏  举报