Given an integer, write a function to determine if it is a power of two.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
1 public class Solution { 2 public boolean isPowerOfTwo(int n) { 3 if(n < 1 ) return false; 4 return (n&(n-1)) == 0; 5 } 6 }