Is this right answer?

  • 5

    Input: 0
    Output: []
    Expected: [0]

  • 0

    This prompt means: given an input of "0", your program generated and output of "[]", but the expected answer is "[0]".

    Therefore, the program is incorrect.

  • 1

    Yes, it is definitely right. There is always 2^n elements in result list.

    When n=0, there should be 2^n = 2^0 = 1 element. You can consider it as an edge case.

  • 0

    I don't think so. Grey code is from hardware domain. There is no n=0 there

  • 0

    how you output [0] when you are asked bit number is 0

  • 0

    The reason why the output is [0] for input [0] is that a gray code sequence must begin with 0 according to the problem statement. Even input is [0] meaning the number of bits is zero, the output starts with zero. Since number of bits is 0, we do not add anything to gray code sequence, so output becomes [0].

  • 0

    Yeah, I don't agree either. If n=0, then, since "...n representing the total number of bits in the code..", every element of the gray code sequence needs to have length 0. So yes, even though the question says every gray code starts with zero, the gray code for n=0, meaning [], does trivially start with zero since it has no length. That test case should be changed.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.