[
math
bit manipulation
]
BinarySearch 0376 Reflected Binary Code
Problem statement
https://binarysearch.com/problems/Reflected-Binary-Code/
Solution
Actually, problem statement is not correct, there are a lot of Gray codes, but we need to choose specific one. Element can be calculated with direct formula.
Complexity
It is O(1)
for time and space.
Code
class Solution:
def solve(self, n):
return n ^ (n >> 1)