Substring Matching Pattern

You are given a string s and a pattern string p, where p contains exactly one '*' character.

The '*' in p can be replaced with any sequence of zero or more characters.

Return true if p can be made a substring of s, and false otherwise.

Example 1
Inputs = "leetcode", p = "ee*e"
Outputtrue
By replacing the '*' with "tcod", the substring "eetcode" matches the pattern.
Example 2
Inputs = "car", p = "c*v"
Outputfalse
There is no substring matching the pattern.

Constraints

  • 1 <= s.length <= 50
  • 1 <= p.length <= 50
  • s contains only lowercase English letters.
  • p contains only lowercase English letters and exactly one '*'

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate