206. Word Pattern II

MediumBacktracking

Given a `pattern` and a string `s`, return `true` if `s` **matches** the `pattern`. A string `s` **matches** a `pattern` if there is some **bijective mapping** of single characters to **non-empty** strings such that if each character in `pattern` is replaced by the string it maps to, then the resulting string is `s`. A **bijective mapping** means that no two characters map to the same string, and no character maps to two different strings.

Examples

Input: abab redblueredblue

Output: true

Explanation: a→red, b→blue reproduces the string.

Constraints

  • 1 <= pattern.length <= 20
  • 1 <= s.length <= 50
  • pattern and s consist of only lowercase English letters.
Loading...

Run checks all cases above. Submit evaluates all test cases.