[LeetCode]Power of Two

public class Solution {
    public boolean isPowerOfTwo(int n) {
        int tmp = 1;
        for (int j = 0; j < 32; j++) {
            if (n == tmp) {
                return true;
            }
            if (tmp > n) {
                return false;
            }
            tmp = tmp << 1;
        }
        return false;
    }
}

 

posted @ 2015-11-27 04:44  Weizheng_Love_Coding  阅读(109)  评论(0编辑  收藏  举报