#89

LeetCode:Gray Code

泄露秘密 提交于 2020-03-01 21:07:54
1、题目名称 Gray Code(格雷码) 2、题目地址 https://leetcode.com/problems/gray-code/ 3、题目内容 英文: 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. 中文: 格雷码是一个二进制数字系统,在该系统中两个相邻的数字仅相差1个二进制位(比特)。 给出一个非负数字n,打印由n个二进制位组成的格雷码序列。格雷码序列的首个元素必须是0。 说明: 在n给定的情况下,按照上面定义(两个相邻数字仅相差1个二进制位),可以有多种格雷码的编码方案。比如n=2时,除了[0,1,3,2]外,[0,2,3,1]也是满足定义的,目前的OJ校验时只支持一种格雷码的编码方案,对此我们(出题人)表示抱歉。 4、解题方法 在题目说明中已经说明了“只支持一种格雷码的编码方案”