609. Find Duplicate File in System

来源:互联网 发布:双色球行情分析软件 编辑:程序博客网 时间:2024/06/05 11:14

找内容相同的元素

class Solution(object):
    def findDuplicate(self, paths):
        """
        :type paths: List[str]
        :rtype: List[List[str]]
        """
        M = collections.defaultdict(list)
        for line in paths:
            data = line.split()
            root = data[0]
            for file in data[1:]:
                name, _, content = file.partition('(')
                M[content[:-1]].append(root + '/' + name)
                
        return [x for x in M.values() if len(x) > 1]

原创粉丝点击