Question:
Given an integer, write a function to determine if it is a power of two.
Example:
Input: 1Output: trueExplanation: 20 = 1
Input: 16Output: trueExplanation: 24 = 16
Input: 218Output: false
Solution:
/*** @param {number} n* @return {boolean}*/var isPowerOfTwo = function(n) {let m = 1;let j = 0while( m < n ) {m = Math.pow(2,j)j++;}return m === n};
Runtime: 100 ms, faster than 30.00% of JavaScript online submissions for Power of Two.
