Input "" should return 1 instead of 0


  • 30
    Y

    There is 1 way to decoding "", the decoding result is "".


  • 0
    S

    Agree. For those abnormal input, also need to return 0, like '2002', '0123' and '3021'


  • 0
    R

    Agree. I guess they will put these abnormal cases into the judge cases.


  • 6
    Y

    Disagree.
    The question's following mapping is:

    'A' -> 1
    'B' -> 2
    ...
    'Z' -> 26

    There is no "" in it.

    So, "" is also abnormal input, which need to return 0, like '2002', '0123' and '3021'


  • 0

    I think the reason they didn't care about abnormal input is this:

    "Given an encoded message containing digits", no letter indicates "0",

    So there is no way you can encode a message to: "2002" or "0123"


  • 1
    M

    @JellyDG But actually, "0" is one of their test cases.


  • 0
    L

    The task is

    Given an encoded message containing digits, determine the total number of ways to decode it.

    So the input string MUST BE a valid encoded message. Otherwise the task could be formulated like this:

    Given a string (containing digits), determine the total number of ways to decode it, or return 0 if it is not a valid encoded message.


Log in to reply
 

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