You are given a pattern string and another string s.
Determine whether s follows the same pattern as described below:
• Each character in the pattern corresponds to exactly one unique word in s.
• Each word in s corresponds to exactly one unique character in the pattern.
• There is a one-to-one mapping (bijection) between pattern characters and words.
If such a mapping exists, return true; otherwise, return false.
Input: pattern = "xyyx" s = "apple banana banana apple"
Output: true
Input: pattern = "xyyx" s = "apple banana banana kiwi"
Output: false
Input: pattern = "xxxx" s = "apple banana banana apple"
Output: false
Accepted:
Submission: