Observing case with
n with its sub-problem with
n-1, we can find a reverse-and-add relation. That leads to code below.
class Solution(object): def grayCode(self, n): """ :type n: int :rtype: List[int] """ results =  # base case for i in range(n): # get most significant bit value msb = 2**i results += [msb + num for num in results[::-1]] return results # run in 42 ms