Python naive solution


  • 0
    L
    class Solution(object):
        def findTheDifference(self, s, t):
            for x in t:
                if x not in s:
                    return x
            d1={}
            d2={}
            for x in s:
                if d1.get(x)==None:
                    d1[x]=1
                else:
                    d1[x]+=1
            for x in t:
                if d2.get(x)==None:
                    d2[x]=1
                else:
                    d2[x]+=1
            print(d1)
            print(d2)
            for keys1,keys2 in zip(d1.keys(),d2.keys()):
                if(d1.get(keys1)!=d2.get(keys2)):
                    return keys1```
            return None`

Log in to reply
 

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