Python 70ms AC solution sharing using hash table


  • 1
    R
    def isIsomorphic(self, s, t):
        if len(s) != len(t):
            return False
        def halfIsom(s, t):
            res = {}
            for i in xrange(len(s)):
                if s[i] not in res:
                    res[s[i]] = t[i]
                elif res[s[i]] != t[i]:
                    return False
            return True
        return halfIsom(s, t) and halfIsom(t, s)

Log in to reply
 

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