When n = 0, it should return []


  • 17
    S

    n = 0 mean the length is 0, so the program should return [].

    Go fix the test case please.


  • 0
    G

    I am thinking about the same thing


  • 1
    L

    Actually, for n = 0, 2^n = 1, so [0] is the correct answer.


  • 0
    L

    n means the lenght, so for n=0, it should return []


  • 0
    L

    the length of |0| is 0, so [0] are all the codes of length 0. [0] is correct, not []


  • 0
    F

    It should not be [0], but [special empty-string symbol]. From wikipedia: "The one-bit Gray code is G1 = (0, 1). This can be thought of as built recursively as above from a zero-bit Gray code G0 = ( Λ ) consisting of a single entry of zero length."


  • 0
    K

    I think it should return [] and not [0].
    The question clearly says: "Given a non-negative integer n representing the total number of bits in the code,".
    n=0 implies total number of bits in code is 0. So no bits in gray code. How can we expect a 0 in output, when one bit is required to represent 0 in gray code.
    Question doesn't say anything about considering 2^0, or any length, as is pointed out by few guys in comments. It didn't even ask us to refer to its definition from Wikipedia.


Log in to reply
 

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