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 [0,1,3,2]. Its
gray code sequence is:
00 - 0
01 - 1
11 - 3
10 - 2
题意:这道题要求相邻两个数有且仅有一位不同,并且第一个和最后一个数也满足要求。
思路:好吧,由于本人本科是学通信的,一看到这道题就知道这是大名......
阅读全文