#44

Wildcard Matching

international master · 1935 · lc hard +32 · verified · 31.5% accepted · 9,079 likes · top 9%

play →

Description

Implement wildcard pattern matching for string s against pattern p, where '?' matches any single character and '*' matches any sequence of zero or more characters. The entire input string must be covered.

Example 1:

Input: s = "aa", p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".

Example 2:

Input: s = "aa", p = "*"
Output: true
Explanation: '*' matches any sequence.

Example 3:

Input: s = "cb", p = "?a"
Output: false
Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'.

Code

1
2
3