https://leetcode.com/problems/word-pattern/
class Solution:
def wordPattern(self, pattern: str, s: str) -> bool:
if len(pattern) != len(s.split()):
return False
d, ov = {}, set([])
for a, b in zip(list(pattern), list(s.split())):
if a in d and d[a] != b:
return False
if a not in d :
d[a] = b
ov.add(b)
return len(ov) == len(d)
생각보다 어려워서 당황당황...
split()을 잘 쓰자 분명 더 쉽게 풀 수 있겠지만...
댓글 0