Isomorphicstrings

Source: Internet
Author: User
Keywords Mapping relationship Isomorphicstrings
Tags check class code coding return set type

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.