[Leecode] C# 89.格雷编码

[Leecode] C# 89.格雷编码

题目要求

[Leecode] C# 89.格雷编码

解题思路

关键是要找到规律
n = 0, [0]
n = 1, [0,1] //新的元素1,为0+2^0
n = 2, [0,1,3,2] // 新的元素[3,2]为[0,1]->[1,0]后分别加上2^1
n = 3, [0,1,3,2,6,7,5,4] // 新的元素[6,7,5,4]为[0,1,3,2]->[2,3,1,0]后分别加上2^2->[6,7,5,4]

代码

[Leecode] C# 89.格雷编码