Easy to follow Python solution using xor

  • 0
    class Solution(object):
        def findTheDifference(self, s, t):
            :type s: str
            :type t: str
            :rtype: str
            assert len(s) + 1 == len(t)
            result = 0
            for i, ch in enumerate(t):
                result ^= ord(ch)
                if i < len(t) - 1:
                    result ^= ord(s[i])
            return chr(result)

Log in to reply

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