1 class Solution { 2 public: 3 /* 4 * @param n: An integer 5 * @return: True or false 6 */ 7 bool checkPowerOf2(int n) { 8 // write your code here 9 return n > 0 && ((n & (n - 1)) == 0); 10 } 11 };
时间: 2024-10-27 09:21:57
1 class Solution { 2 public: 3 /* 4 * @param n: An integer 5 * @return: True or false 6 */ 7 bool checkPowerOf2(int n) { 8 // write your code here 9 return n > 0 && ((n & (n - 1)) == 0); 10 } 11 };