Leetcode389.find the difference

def findTheDifference(s, t):
    s_dict = {}
    for x in s:
        if x in s_dict:
            s_dict[x] += 1
        else:
            s_dict[x] = 1

    for y in t:
        if y not in s_dict or s_dict[y] == 0:
            return y
        else:
            s_dict[y] -= 1

 

你可能感兴趣的:(leetcode)