# """02-08-2022 Leetcode 389. Find The Difference""" # # You are given two strings s and t. # # String t is generated by random shuffling string s and then add one more letter at a # # random position. Return the letter that was added to t. # from typing import Counter s = "abcd" t = "abcde" # s = Counter(s) # t = Counter(t) - s # for i in t.keys(): # print(i) # Initialize ch with 0, because 0 ^ X = X # 0 when XORed with any bit would not change the bits value. ch = 0 # XOR all the characters of both s and t. for char_ in s: ch ^= ord(char_) for char_ in t: ch ^= ord(char_) # What is left after XORing everything is the difference. print( chr(ch) )