Gray Code
Solution Code
class Solution:def grayCode(self, n: int) -> List[int]:return [i ^ (i >> 1) for i in range(1 << n)]Time Complexity
O(2^n)
Space Complexity
O(1) (excluding the space required for the output list)
class Solution:def grayCode(self, n: int) -> List[int]:return [i ^ (i >> 1) for i in range(1 << n)]