Problem · String
Word Pattern II (Round 1, LC 291 :)
Learn this problemProblem statement
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.
🌷 wallz carries! 🌷
Function
wordPatternMatch(pattern: String, s: String) → booleanExamples
Example 1
pattern = "abab"s = "redblueredblue"return = trueOne possible mapping is as follows:
- 'a' -> "red"
- 'b' -> "blue"
Example 2
pattern = "aaaa"s = "asdasdasdasd"return = trueOne possible mapping is as follows:
- 'a' -> "asd"
Example 3
pattern = "aabb"s = "xyzabcxyzabc"return = falseNo possible mapping exists that can satisfy the given pattern and string.
Constraints
1 <= pattern.length, s.length <= 20patternandsconsist of only lowercase English letters.