Leetcode 609 Solution
This article provides solution to leetcode question 609 (find-duplicate-file-in-system)
Access this page by simply typing in "lcs 609" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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])