Python regexp + dict


  • 0
    D
    class Solution(object):
        def findDuplicate(self, paths):
            """
            :type paths: List[str]
            :rtype: List[List[str]]
            """
            hash = collections.defaultdict(list)
            match = re.compile('(.*)\((.*)\)')
            for p in paths:
                strlist = p.split()
                for i in range(1, len(strlist)):
                    m = match.search(strlist[i])
                    hash[m.group(2)].append(strlist[0] + '/' + m.group(1))
            return [l for l in hash.values() if len(l) > 1]
    

Log in to reply
 

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