python AC solution


  • 0
    A
    class Solution(object):
        def findDuplicate(self, paths):
            """
            :type paths: List[str]
            :rtype: List[List[str]]
            """
            dic = {}
    
            for path in paths:
                p = path.split()
                directory, files = p[0], p[1:]
        
                for file in files:
                    key = re.findall('\(\w+\)', file)[0]
        
                    file_name = file.replace(key, '')
        
                    dic[key] = dic.get(key, []) + [directory + '/' + file_name]
        
        
            return [v for v in dic.values() if len(v) > 1]
            
    

Log in to reply
 

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