Pattern Matching
Patterns are made of lower-case letters and two special characters:
.matches any single character,*matches zero or more of the character (or.) just before it.
Return true if the pattern p matches the whole of s, not just a part of it.
Constraints
- 0 ≤ length of
s≤ 25 - 1 ≤ length of
p≤ 30 shas lower-case letters;phas lower-case letters,.and*, and every*comes right after a letter or..
Example 1
Input
s = "aa"
p = "a"
Output
false
Why:
a matches only one character, and the whole string must match.
Example 2
Input
s = "aa"
p = "a*"
Output
true
Why:
a* matches any number of as, two among them.
Example 3
Input
s = "ab"
p = ".*"
Output
true
Why:
.* matches anything.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –