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

leetcode_231 Power Of Two(Bit Manipulation)

时间:2017-04-24 00:59:28      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:cti   ==   ret   amp   tco   ati   位运算   log   power   

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

public class Solution {
    public boolean isPowerOfTwo(int n) {
        return ((n&(n-1))==0&&n>0);
    }
}

强大的位运算!!!

leetcode_231 Power Of Two(Bit Manipulation)

标签:cti   ==   ret   amp   tco   ati   位运算   log   power   

原文地址:http://www.cnblogs.com/ytq1016/p/6754762.html

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