Python with regex solution


  • 0
    class Solution(object):
        def findDuplicate(self, paths):
    		import re
    		f_dic = {}
    		for path in paths:
    			dir_p = 'root\S*'
    			file_p = '(\w+\.txt)\((\w+)\)'
    			direc = re.findall(dir_p, path)[0]
    			files = re.findall(file_p, path)
    			for file in files:
    				name, content = file
    				if not content in f_dic:
    					f_dic[content] = [direc+'/'+name]
    				else:
    					f_dic[content].append(direc+'/'+name)
    		return [v for v in f_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.