mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-26 21:58:56 +01:00
Update power_of_two.rb
This commit is contained in:
parent
24acbadd4f
commit
b28aa0a252
1 changed files with 5 additions and 0 deletions
|
@ -119,6 +119,11 @@ puts is_power_of_two(n)
|
|||
# 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
|
||||
#
|
||||
# Time complexity: O(1).
|
||||
|
|
Loading…
Reference in a new issue