Leetcode 609 Solution

This article provides solution to leetcode question 609 (find-duplicate-file-in-system)

https://leetcode.com/problems/find-duplicate-file-in-system

Solution

class Solution:
    def findDuplicate(self, paths: List[str]) -> List[List[str]]:
        m = collections.defaultdict(list)

        for path in paths:
            tokens = path.split(' ')

            directory = tokens[0]

            for filename_and_content in tokens[1:]:
                filename, content = filename_and_content.split('(')
                content = content[:-1]
                m[content].append("{}/{}".format(directory, filename))

        return list([files for files in m.values() if len(files) > 1])