In this video I explain the algorithm behind solving Leetcode problem #231 Power of Two. Here I count the number of set (1) bits as explained in #191 Number of 1 Bits ( • Explaining Leetcode #191 Number of 1 Bits ... ) and using it to find if a number is a power of two.
I am coding in Java since its syntax is easy to understand by all programmers. The algorithms can be applied easily in other languages and most functions that I use have a counterpart in your language of choice.
0:00 Explaining the problem concept
1:33 First coding attempt and its problem
3:24 Fixing the problem and reaching an optimal solution
Related Topics: Math, Bit Manipulation