diff --git a/problems/0205.同构字符串.md b/problems/0205.同构字符串.md index a2963149..eeda7d2e 100644 --- a/problems/0205.同构字符串.md +++ b/problems/0205.同构字符串.md @@ -90,6 +90,24 @@ class Solution { ## Python ```python +class Solution: + def isIsomorphic(self, s: str, t: str) -> bool: + default_dict1 = defaultdict(str) + default_dict2 = defaultdict(str) + + if len(s) != len(t): return false + + for i in range(len(s)): + if not default_dict1[s[i]]: + default_dict1[s[i]] = t[i] + + if not default_dict2[t[i]]: + default_dict2[t[i]] = s[i] + + if default_dict1[s[i]] != t[i] or default_dict2[t[i]] != s[i]: + return False + + return True ``` ## Go