Isomorphic strings
October 21, 2022
array-and-hashmapProblem URL: Isomorphic strings
We can iterate over both string at the same time and look for the first occurrence of each character. If the first occurrence of the character in both strings is not the same, then we will return false. Otherwise, we will return true.
class Solution:
def isIsomorphic(self, s: str, t: str) -> bool:
for i, j in zip(s, t):
if s.find(i) != t.find(j):
return False
return True
Time Complexity: O(n)
Space Complexity: O(1)