天天看點

Gray Code

the gray code is a binary numeral system where two successive values differ in only one bit.

given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. a gray code sequence must begin with 0.

for example, given n = 2, return <code>[0,1,3,2]</code>. its gray code sequence is:

note:

for a given n, a gray code sequence is not uniquely defined.

for example, <code>[0,2,3,1]</code> is also a valid gray code sequence according to the above definition.

for now, the judge is able to judge based on one instance of gray code sequence. sorry about that.