Python and Dictionary based solution


  • 0
    C

    """
    class Solution(object):
    def isIsomorphic(self, s, t):
    """
    :type s: str
    :type t: str
    :rtype: bool
    """
    f_dict = {}
    for i in range(len(s)):

            if s[i] in f_dict.keys():
                continue
            if t[i] not in f_dict.values():
                f_dict[s[i]] = t[i]
            else:
                f_dict[s[i]] = ""                 
                    
    
        gen_string = ""
        for i in range(len(s)):
            
            gen_string  = gen_string + f_dict[s[i]]
        if gen_string == t:
            return True
        else:
            return False  
    

    """


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.