Given two strings s and t which consist of only lowercase letters.

String t is generated by random shuffling string s and then add one more letter at a random position.

Find the letter that was added in t.

Example:

Input:
s = "abcd"
t = "abcde"

Output:
e

Explanation:
'e' is the letter that was added.

Source: leetcode | Difficulty: EASY
Tags: String algorithms

Bit manipulation

Sorting

Data structures

Starter code: class Solution:
    def findTheDifference(self, s: str, t: str) -> str:
        

Solutions:
class Solution:

	def findTheDifference(self, s, t):
		sums = (sum([ord(i) for i in s]), sum([ord(i) for i in t]))
		return chr(sum([ord(i) for i in t]) - sum([ord(i) for i in s]))


class Solution:

	def findTheDifference(self, s, t):
		s_dict = {}
		for letter in s:
			if letter not in s_dict:
				s_dict[letter] = 1
			else:
				s_dict[letter] += 1
		t_dict = {}
		for letter in t:
			if letter not in t_dict:
				t_dict[letter] = 1
			else:
				t_dict[letter] += 1
		result = ''
		for letter in t:
			if letter not in s_dict:
				result = letter
			elif t_dict[letter] > s_dict[letter]:
				result = letter
		return result


class Solution:

	def findTheDifference(self, s, t):
		ss = sorted(s)
		st = sorted(t)
		i = 0
		j = 0
		while i <= len(ss) - 1:
			if ss[i] == st[j]:
				i += 1
				j += 1
			else:
				return st[j]
		return st[j]


class Solution:

	def findTheDifference(self, s, t):
		return [i for i in t if i not in s or s.count(i) != t.count(i)][0]


class Solution:

	def findTheDifference(self, s, t):
		s_map = {}
		for char in s:
			if char in s_map:
				s_map[char] += 1
			else:
				s_map[char] = 1
		t_map = {}
		for char in t:
			if char in t_map:
				t_map[char] += 1
			else:
				t_map[char] = 1
		for char in t_map:
			if char not in s_map or t_map[char] > s_map[char]:
				return char


class Solution:

	def findTheDifference(self, s, t):
		a = list(s)
		b = list(t)
		for c in s:
			a.remove(c)
			b.remove(c)
		return b[0]


class Solution:

	def findTheDifference(self, s, t):
		S = [i for i in s]
		T = [i for i in t]
		for i in S:
			T.remove(i)
		return T[0]