Practice/Google/Leetcode 290. Word Pattern
CodingMust
You are given a pattern string containing lowercase letters and a string s containing words separated by single spaces. Determine whether there exists a bijective (one-to-one and onto) correspondence between the characters in the pattern and the words in s.
A valid bijection means:
ss maps to exactly one unique character in the patternReturn true if such a bijection exists, otherwise return false.
sExample 1:
Input: pattern = "abba", s = "dog cat cat dog" Output: true Explanation: The bijection is: a ↔ dog, b ↔ cat Applying the mapping to "abba" gives "dog cat cat dog"
Example 2:
Input: pattern = "abba", s = "dog cat cat fish" Output: false Explanation: Letter 'a' would need to map to both "dog" and "fish", which violates the bijection property.
Example 3:
Input: pattern = "aaaa", s = "dog dog dog dog" Output: true Explanation: Letter 'a' consistently maps to "dog" throughout the entire pattern.
Example 4:
Input: pattern = "abba", s = "dog dog dog dog" Output: false Explanation: Both 'a' and 'b' would map to "dog", violating the one-to-one requirement.