Match a Pattern With ? and *
Problem statement
You are given a string s and a pattern p. In the pattern:
- a letter matches that same letter,
?matches exactly one letter, any letter,*matches any run of letters, including no letters at all.
Return true if the pattern matches the whole string s, and false otherwise.
Function
isWildcardMatch(s: String, p: String) → booleanExamples
Example 1
s = "banana"p = "b*n?"return = trueb matches the first letter, * takes "ana", n matches the fifth letter and ? takes the last a: true.
Example 2
s = "cat"p = "c?t?"return = falseWithout stars the pattern matches exactly 4 characters, but "cat" has 3: false.
Example 3
s = ""p = "**"return = trueEach * may match nothing, so two stars match the empty string: true.
Constraints
0 <= s.length, p.length <= 1000scontains only lowercase English letterspcontains only lowercase English letters,'?'and'*'