Description
Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between pattern and words in s.
Examples
Input:
pattern = "abba", s = "dog cat cat dog"Output:
trueExplanation:
Bijection exists.
Input:
pattern = "abba", s = "dog cat cat fish"Output:
falseExplanation:
Pattern maps a->dog and b->cat, but then a should map to dog while the 4th word is "fish".
Input:
pattern = "abc", s = "red blue red"Output:
falseExplanation:
Pattern 'a' maps to 'red', 'b' maps to 'blue', but 'c' also tries to map to 'red'. Since 'red' is already mapped to 'a', the bijection fails.
Constraints
- •
1 ≤ pattern.length ≤ 300