标签:
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 bool isPowerOfTwo(int n) 2 { 3 while (n > 1) 4 { 5 if (n & 1) 6 { 7 break; 8 } 9 n = (n >> 1); 10 } 11 12 return (n == 1); 13 }
标签:
原文地址:http://www.cnblogs.com/ym65536/p/5493167.html