Practice/Amazon/Leetcode 10. Regular Expression Matching
CodingOptional
You are given a text string and a pattern string. Implement a function that determines whether the pattern matches the entire text string.
The pattern may contain two special characters:
. (dot) — matches any single character* (asterisk) — matches zero or more of the immediately preceding characterThe matching must cover the entire text string, not just a portion of it.
true if the pattern matches the entire text, otherwise return false* operator applies to the character immediately before it. character can match any single character including letters, digits, and symbols* can be applied to . as well (e.g., .* matches zero or more of any character)text contains only lowercase English letterspattern contains only lowercase English letters, ., and ** always has a preceding characterExample 1:
Input: text = "aa", pattern = "a" Output: false Explanation: The pattern "a" only matches one character, but the text has two characters.
Example 2:
Input: text = "aa", pattern = "a*" Output: true Explanation: The "a*" pattern matches two 'a' characters (one or more occurrences).
Example 3:
Input: text = "ab", pattern = ".*" Output: true Explanation: The ".*" pattern matches any sequence of characters, including "ab".
Example 4:
Input: text = "aab", pattern = "c*a*b" Output: true Explanation: "c*" matches zero 'c's, "a*" matches two 'a's, and "b" matches 'b'.