Update power_of_two.rb

This commit is contained in:
Vitor Oliveira 2021-03-19 20:59:40 -07:00 committed by GitHub
parent 24acbadd4f
commit b28aa0a252
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -119,6 +119,11 @@ puts is_power_of_two(n)
# Approach 4: Bitwise operators: Turn off the Rightmost 1-bit # Approach 4: Bitwise operators: Turn off the Rightmost 1-bit
# #
# Note that there are two ways of solving this problem via bitwise operations:
# 1. How to get / isolate the rightmost 1-bit: x & (-x).
# 2. How to turn off (= set to 0) the rightmost 1-bit: x & (x - 1).
# In this approach, we're reproducing item 2.
# Complexity Analysis # Complexity Analysis
# #
# Time complexity: O(1). # Time complexity: O(1).