python solution that is easy to understand


  • 0
    import collections
    class Solution(object):
        def findTheDifference(self, str1, str2):
            """
            :type str1: str
            :type str2: str
            :rtype: str
            """
            #str2->str1
            m=len(str1)
            n=len(str2)
            cnt1=collections.Counter(str1)
            cnt2=collections.Counter(str2)
            diff=cnt2-cnt1
            res=''
            for x in diff.keys():
                c=diff[x]
                for i in range(c):
                    res+=x
            return res
    

Log in to reply
 

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