Given an integer, write a function to determine if it is a power of two.

    Example 1:

    1. Input: 1
    2. Output: true
    3. Explanation: 20 = 1

    Example 2:

    1. Input: 16
    2. Output: true
    3. Explanation: 24 = 16

    Example 3:

    1. Input: 218
    2. Output: false
    1. /**
    2. * @param {number} n
    3. * @return {boolean}
    4. */
    5. var isPowerOfTwo = function(n) {
    6. if (n < 1) {
    7. return false;
    8. }
    9. while(n > 1) {
    10. if (parseInt(n % 2) !== 0) {
    11. return false;
    12. }
    13. n = parseInt(n /2);
    14. }
    15. return true;
    16. };
    /**
     * @param {number} num
     * @return {boolean}
     */
    var isPowerOfTwo = function(num) {
        if (num < 1) {
            return false;
        }
        const bits = num.toString(2);
        for (let i = 1; i < bits.length; i++) {
          if (bits[i] !== '0') {
            return false;
          }
        }
        return true;
    };
    
    /**
     * @param {number} n
     * @return {boolean}
     */
    var isPowerOfTwo = function(n) {
        if (n < 1) {
            return false;
        }
        return (n & (n - 1)) === 0;
    };