Facebook Pixel

Power of Two

JavaScript
easy
20 mins

Determine if a given integer is a power of two using efficient bit manipulation techniques.

Problem

Given an integer n, return true if it is a power of two. Otherwise, return false.

A number is a power of two if there exists an integer x such that n === 2^x.

Examples

Input: n = 1 Output: true Explanation: 2^0 = 1 Input: n = 16 Output: true Explanation: 2^4 = 16 Input: n = 3 Output: false Explanation: 3 is not a power of 2 Input: n = 0 Output: false Explanation: 0 is not a power of 2

Constraints

  • -2^31 ≤ n ≤ 2^31 - 1
  • Return false for:
    • n ≤ 0
    • non-integer inputs

Companies:

adobe
google
amazon
oracle

Solve Similar questions 🔥

Please Login.
Please Login.