Power of Two - aloalgo

Power of Two

Easy

You are given a non-negative integer n.

Your task is to determine whether n is a power of two.

You may assume that:

  • n is a non-negative integer.

Return true if n is a power of two, and false otherwise.

Example 1

Input
8
Output
True
Explanation:

8 in binary is 1000, which has exactly one set bit, so it is a power of two (2^3 = 8).

Example 2

Input
5
Output
False
Explanation:

5 in binary is 101, which has more than one set bit, so it is not a power of two.

Example 3

Input
0
Output
False
Explanation:

0 is not a power of two.

Loading...
Input
8
Output
True

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!