Easy python solution using dictionary


  • 0
    A
    def findTheDifference(self, s, t):
        sDic = {}
        tDic = {}
        for letter in s:
            if letter not in sDic:
                sDic[letter] = 1
            else:
                sDic[letter] += 1
        for letter in t:
            if letter not in tDic:
                tDic[letter] = 1
            else:
                tDic[letter] += 1
        for i in t:
            if (i not in s) or (tDic[i] != sDic[i]):
                return i

Log in to reply
 

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