题目要求:
跟上一个字符串的思路一致,只是要进行单词的拆分,用.split()函数即可。
class Solution:
def wordPattern(self, pattern: str, s: str) -> bool:
word = s.split()
if(len(pattern) != len(word)):
return False
return len(set(pattern)) == len(set(word)) == len(set(zip(pattern,word)))