class Solution:
def wordPattern(self, pattern: str, s: str) -> bool:
pattern_list = list(pattern)
string_split = s.split()
if len(set(pattern_list)) != len(set(string_split)) or len(pattern) != len(string_split):
return False
table = dict()
for i, j in zip(pattern, s.split()):
if i not in table:
table[i] = j
else:
if table[i] != j:
return False
return True
class Solution:
def wordPattern(self, pattern: str, s: str) -> bool:
p = pattern
t = s.split()
return map(p.find, p) == map(t.index, t)
그리고 댓글
나도 울었다