contract mapping1 [LeetCode] Word Pattern 파이썬 (isomorphic, contract mapping) class Solution: def wordPattern(self, pattern: str, s: str) -> bool: s = list(s.split(" ")) if len(pattern) != len(s): return False s2t, t2s = {}, {} for p, w in zip(pattern, s): if w not in s2t and p not in t2s: s2t[w] = p t2s[p] = w elif w not in s2t or s2t[w] != p: # Contradict mapping. return False return True 이 문제를 본 순간 [LeetCode] Isomorphic Strings 문제가 떠올랐다. ygseo.tistory.com/221 len으로 먼저 .. 2021. 4. 12. 이전 1 다음