My 1 line Python solution


  • 2

    I know we can use variable to store intermediate result, that will improve performance.
    This solution causes quadruple running time. But as long as time complexity is O(n), who care the performance.

    class Solution:
        # @param {string} s
        # @param {string} t
        # @return {boolean}
        def isIsomorphic(self, s, t):
            return dict(zip(s, t)) == dict(reversed(zip(s, t))) and dict(zip(t, s)) == dict(reversed(zip(t, s)))
    

    THIS SOLUTION IS WRONG!


  • 0
    A

    I tried your solution with s = 'aba' and t = 'aaa'. It returned True while the answer should be False. I think your algorithm can't deal with the situation when the difference only happens in the middle of the string?!


  • 0

    Yes, you're right.


Log in to reply
 

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