首页 > 其他 > 详细

Power of Two

时间:2015-12-16 22:46:00      阅读:234      评论:0      收藏:0      [点我收藏+]

Power of Two

Total Accepted: 43421 Total Submissions: 130315 Difficulty: Easy

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

class Solution {
public:
    bool isPowerOfTwo(int n) {
        long long int m = n;
        return n==0 ? false : (m&(m-1))==0;
    }
};

Next challenges: (M) Bitwise AND of Numbers Range (M) Perfect Squares (H) Best Meeting Point

Power of Two

原文:http://www.cnblogs.com/zengzy/p/5052349.html

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