Python with dict solution /newman


  • 0
    M
    class Solution(object):
        def findTheDifference(self, s, t):
            dict1 = {}
            dict2 = {}
            
            for i in s:
                if i not in dict1:dict1[i] = 0
                dict1[i] +=1
            for j in t:
                if j not in dict2:dict2[j] = 0
                dict2[j] +=1
            
            for i in dict2:
                try:
                    if dict2[i] !=dict1[i]:
                        return i
                except:
                    return i
    

Log in to reply
 

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