[
string
hash table
]
BinarySearch 0279 String Isomorphism
Problem statement
https://binarysearch.com/problems/String-Isomorphism/
Solution
Equal to Leetcode 0205. Isomorphic Strings.
Complexity
It is O(n)
for time and O(26)
for space.
Code
class Solution:
def solve(self, s, t):
d1, d2 = {}, {}
for i, j in zip(s, t):
if i not in d1:
if j in d2: return False
else:
d1[i] = j
d2[j] = i
elif d1[i] != j: return False
return True