view code
```py
from collections import Counter
class Solution:
def wordPattern(self, pattern: str, s: str) -> bool:
words = s.split(" ")
if (len(pattern) != len(words)
or len(Counter(pattern)) != len(Counter(words))):
return False
_dict = {}
for i in range(len(pattern)):
letter, word = pattern[i], words[i]
if letter not in _dict:
_dict[letter] = word
elif _dict[letter] != word:
return False
return True
```
https://leetcode.com/problems/word-pattern/