Short and Clear Python Code? String.translate

  • 0
    class Solution:
    # @param {string} s
    # @param {string} t
    # @return {boolean}
    def isIsomorphic(self, s, t):
        s, t = str(s), str(t)
        table1 = string.maketrans(s, t)
        table2 = string.maketrans(t, s)
        return s.translate(table1) == t and t.translate(table2) == s

Log in to reply

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