Isomorphic Strings LeetCode solution in Python
1class Solution:2def isIsomorphic(self, s: str, t: str) -> bool:3dict1 = {}4m = ""5# creating a dictionary by mapping each element from string S to string T6for i, j in zip(s, t):7# this for the cases like "badc" and "baba" so we dont want two keys mapping to same value hence we can reject directly8if j in dict1.values() and i not in dict1.keys():9return False10dict1[i] = j1112# now take each letter from string s and using dictionary values replace it with that specific character13for k in s:14m = m + dict1[k]1516# now if newly formed string m == T is same then the strings are Isomorphic17if m == t:18return True19else:20return False