...

/

Solution Review: Power of 2

Solution Review: Power of 2

Let's see how we make use of Brain Kernighan's algorithm to achieve this.

Solution review: Brian Kernighan’s algorithm

This is considered faster than the previous naive approach.

In this approach, we count the set bits. If a number is the power of 2, we know that only one set bit is present in its Binary representation.

In binary, we go from right to left with powers of 2.

For example:

202^{0} ...

Access this course and 1400+ top-rated courses and projects.