public class Solution { public boolean isPowerOfTwo1(int n) { if (n < 0) return false; for (int i = 0; i <32; i++) { if (n == (1 << i)) return true; } return false; } public boolean isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; } }
Leetcode - Power of Two
Given an integer, write a function to determine if it is a power of two.
猜你喜欢
转载自likesky3.iteye.com/blog/2235900
今日推荐
周排行