Decode Ways II


  • 0

    Click here to see the full article post


  • 0
    T

    When string is "0", it returns 1, should be 0. To fix it, second = s.charAt(0) == '*' ? 9 : s.charAt(0) == '0' ? 0 : 1;


  • 0

    @travellinglina Thanks for pointing it out. I have fixed the code.


  • 0
    A

    Example 2:
    Input: "1*"
    Output: 9 + 9 = 18

    This is wrong. "1*"'s '*' can vary from 0 to 9 to make "10"(J) to "19"(S) which is 10.
    J(10), K(11), L(12), M(13), N(14), O(15), P(16), Q(17), R(18), S(19), this is 10.

    So 9 + 10 = 19. Not 18, Please correct it. Thank you.


  • 0

    @Aeonaxx * rages from 1 to 9. It cant be 0.


  • 0
    T

    Hi, In the last lined in the below snippet, I believe it should be 17 instead of 15. Since, given that first char is * and second char is *, total no of 2 digit characters are 10,11...26 = 17 (K, L, M, N, O, ....Z)

    Please correct if wrong

    if (s.charAt(i) == '*') {
                    second = 9 * second;
                    if (s.charAt(i - 1) == '1')
                        second = (second + 9 * first) % M;
                    else if (s.charAt(i - 1) == '2')
                        second = (second + 6 * first) % M;
                    else if (s.charAt(i - 1) == '*')
                        second = (second + 15 * first) % M;
                }
    

Log in to reply
 

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