mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
@ -90,6 +90,24 @@ class Solution {
|
|||||||
## Python
|
## Python
|
||||||
|
|
||||||
```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
|
## Go
|
||||||
|
Reference in New Issue
Block a user