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 };
本文共 293 字,大约阅读时间需要 1 分钟。
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 };
转载于:https://www.cnblogs.com/jcliBlogger/p/4612213.html