Given an integer, write a function to determine if it is a power of two. Example No.1 Input: 1 Output: true Explanation: 2^0 = 1 No.2 Input: 16 Output: true Explanation: 2^4 = 16 No.3 Input: 218 Output: false Code 123456 public boolean (int n) { if (n <= 0) return false; return (n & (n - 1)) == 0;} 赞微海报分享
近期评论