Power of Two

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

posted @ 2015-12-16 21:01  zengzy  阅读(119)  评论(0编辑  收藏  举报
levels of contents