Python with XOR


  • 0
    N
    class Solution(object):
        def findTheDifference(self, s, t):
            a= 0         
            for i in s:
                a = a^ord(i)     # (x^a)^a^b^b = x^(a^a)= x^0= x    i.e     extra character in the string t
            for i in t:
                a = a^ord(i)
            return chr(a)
        ```

Log in to reply
 

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