Isomorphicstrings
Write your own code:
#-*-Coding:utf-8-*-class Solution (object): Def isisomorphic (self, S, T): "": Type S:str:type t:str:rtype:bool "" "If Len ( Set (s))!=len (set (t)): #如果拥有的元素就不一样的话 return False #直接返回 Length=len (s) di={} #建立一个dict, where S[i] is the key, T[i is the value i=0 #下标从0开始 while It[i] Di[s[i]]=t[i] #则建立该种映射关系 else: #已经存在某种映射的关系 tt=di.get (s[i]) #取出该值 if tt==t[i]: #该值如果和t [i] equal pass# do not process else: # If the previous mapping value is not equal to the current value return False i+=1 return True
Saw someone else write it, wrote a note.
#-*-Coding:utf-8-*-class Solution (object): Def isisomorphic (self, S, T): "": Type S:str:type t:str:rtype:bool "" "D = {} # Check that the same key is mapped to the same value #例如 s= ' AA ' t= ' ab ' for I in range (len (t)): If s[i] not in d:d[s[i] [t[i] # Check if mapping is correct elif d[s[i] ]!= T[i]: return False # Check if listbox characters mapped to Mahouve character #检查不同的键是否映射到同一个值, for example: s= ' ab ' t= ' AA '. This can be done by the s,t through the top loop temp = set ([]) for K in D:if K] in Temp:return False Temp.add (k)) return True