Practice/Meta/Leetcode 44. Wildcard Matching
CodingMust
You are given a text string and a pattern string containing special wildcard characters. Your task is to determine whether the entire text string matches the pattern according to these rules:
? matches exactly one character (any character)* matches zero or more characters (any sequence, including empty)Return true if the pattern matches the entire text string from beginning to end, and false otherwise.
? wildcard matches exactly one character* wildcard matches any sequence of zero or more characters0 <= text.length, pattern.length <= 2000text contains only lowercase English letterspattern contains only lowercase English letters and the wildcards ? and ** characters efficientlyExample 1:
Input: text = "aa", pattern = "a" Output: false Explanation: The pattern "a" only matches one character, but text has two characters.
Example 2:
Input: text = "aa", pattern = "*" Output: true Explanation: The '*' matches any sequence, including "aa".
Example 3:
Input: text = "cb", pattern = "?a" Output: false Explanation: '?' matches 'c', but then 'a' does not match 'b'.
Example 4:
Input: text = "adceb", pattern = "*a*b" Output: true Explanation: The first '*' matches empty string, 'a' matches 'a', the second '*' matches "dce", and 'b' matches 'b'.
Example 5:
Input: text = "acdcb", pattern = "a*c?b" Output: false Explanation: After 'a' and '*' matching "cd", we have 'c' matching 'c', but then '?' should match exactly one character before 'b'. However, there are two characters remaining ('d' and 'b'), so no valid match exists.