What about ‘*’ can be from 0 to 9


  • 8

    I found '*' in this question can only be 1 to 9. But things may be more complicated when it can also be 0;

    Input: "1*"
    there should be 19 ways:
    (1) from 10 to 19 : 10 ways;
    (2) from A1 to A9: 9 ways;
    then the total ways are 10 + 9 = 19

    Input: "*"
    the first '
    ' can not be set to 0, as 0 is not any character.


  • 0
    Y

  • 0

    @yiyi2 Thanks for mention that. Can you solve the problem if "*" can be 0?


  • 0

    @Xingxing
    I do not think it can be way complicated. The solution should be similar to treating "*" from "1" to "9". You just need some more conditions to think about and add it to the current answer.


  • 0
    M

    @Xingxing said in What about ‘*’ can be from 0 to 9:

    Input: "1*"
    there should be 19 ways:
    (1) from 10 to 19 : 10 ways;
    (2) from A1 to A9: 9 ways;
    then the total ways are 10 + 9 = 19

    I think you are right. There may some error in example 2.
    Anyone else agrees with us?


  • 0

    @myqsh

    For "1*", if " * " can represent "0" to "9".
    All the valid conditions are, "1" + "1 to 9", "10" to "19".
    Currently, conditions like a single "0" and pairs like "30" are invalid. I do not think there is a big difference after adding "0" to " * ". Just change a little code based on the current dp solution.


Log in to reply
 

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