How come "ab" and ".*" is a match?


  • 6
    C

    Here is the output:

    Input: "ab", ".*"
    Output: false
    Expected: true


  • 15
    K

    As said in the question,
    '.' Matches any single character.
    '*' Matches zero or more of the preceding element.

    Hence ".*" means many "." .

    One "." matches one character, many "." match many characters;

    Thus, we could know ".*" matches all the strings include "".

    That's the reason why "ab" and ".*" come to be a match.


  • 1
    H

    why "." would math ""?
    I think "
    " here represents 0-Infinity ".", so the string should be 1 to infinity "."


Log in to reply
 

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