Python Hashmap Solution


  • 0
    Y
        def findDuplicate(self, paths):
            """
            :type paths: List[str]
            :rtype: List[List[str]]
            """
            mp={}
            res=[]
            for s in paths:
               tags=s.split(" ")
               for i in xrange(1,len(tags)):
                   idx1=tags[i].find("(")
                   idx2=tags[i].find(")")
                   content=tags[i][idx1+1:idx2]
                   if mp.has_key(content):
                       mp[content].append((tags[0],tags[i][:idx1]))
                   else:
                       mp[content]=[ (tags[0],tags[i][:idx1])]
    
            for key in mp:
                if len(mp[key])>1:
                    group=[]
                    for x in mp[key]:
                        s=x[0]+"/"+x[1]
                        group.append(s)
                    res.append(group)
            return res  
    

Log in to reply
 

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