""" 0389.1 - Find the Difference - Solution 1 - Counter Approach """
#####################################################################################
# Imports
#####################################################################################
from collections import Counter
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def findTheDifference(self, s: str, t: str) -> str:
"""Find the Difference Function"""
count = Counter(s)
for char in t:
if count[char] == 0:
return char
count[char] -= 1
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().findTheDifference("abcd", "abcde"))
print(Solution().findTheDifference("", "y"))
print(Solution().findTheDifference("a", "aa"))
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0389.2 - Find the Difference - Solution 2 - XOR Approach """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def findTheDifference(self, s: str, t: str) -> str:
"""Find the Difference Function"""
result = 0
for char in s:
result ^= ord(char)
for char in t:
result ^= ord(char)
return chr(result)
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().findTheDifference("abcd", "abcde"))
print(Solution().findTheDifference("", "y"))
print(Solution().findTheDifference("a", "aa"))
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0389.3 - Find the Difference - Solution 3 - ASCII Sum Approach """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def findTheDifference(self, s: str, t: str) -> str:
"""Find the Difference Function"""
return chr(sum(ord(c) for c in t) - sum(ord(c) for c in s))
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().findTheDifference("abcd", "abcde"))
print(Solution().findTheDifference("", "y"))
print(Solution().findTheDifference("a", "aa"))
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()