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); } }
强大的位运算!!!
时间: 2024-10-19 17:48:14
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); } }
强大的位运算!!!