Why is "a" "ac**" false but "a" "ac***" true again?


  • 0
    Z

    Why is "a" "ac**" false but "a" "ac***" true again? Shouldn't they be all true or all false?


  • 0

    From your previous post it looks like you know Java. What does Java tell you for "a".matches("ac**") and "a".matches("ac***")?


  • 0
    A

    because ac** at most canceled to get "ac** -> a* not good

    the end star of ac*** canceled the last second star get a c* **


  • 0
    R

    For "a" "ac**", the matching process is:
    a --> a: true;
    a --> a | c: false;
    a --> a | c* (empty): true;
    a --> ac | ** (empty): false;
    For "a" "ac***", the matching process is:
    a --> a: true;
    a --> a | c: false;
    a --> a | c* (empty): true;
    a --> ac | ** (empty): false;
    a --> a | c*(empty) | ** (empty): true;
    The key is that there exists some division of p matching s, not for all divisions.


Log in to reply
 

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