题解 | #微信红包#
生成格雷码
http://www.nowcoder.com/practice/50959b5325c94079a391538c04267e15
-- coding:utf-8 --
class GrayCode: def getGray(self, n): # write code here
if n==1:
tmp=['0','1']
else:
tmp=['0'+i for i in self.getGray(n-1)]+['1'+i for i in self.getGray(n-1)[::-1]]
return tmp
tmp=['0','1']
for i in range(1,n):
left=['0'+_ for _ in tmp]
right=['1'+_ for _ in tmp[::-1]]
tmp=left+right
return tmp