44. Wildcard Matching

problem description

Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.

'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).

The matching should cover the entire input string (not partial).

Note:

  • s could be empty and contains only lowercase letters a-z.

  • p could be empty and contains only lowercase letters a-z, and characters like ? or *.

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:

Example 4:

Example 5:

algorithm thought

这题很之前的正则表达式很像,其实还简单一点。使用二维数组保存中间结果,动态规划解决问题。可以借鉴前面动态规划题目的解答。这里的?其实和之前的.一样。这里的*比之前的*更加加单

code

algorithm analysis

时间复杂度O(n²)

Last updated