[LeetCode] Find Duplicate File in System 在系统中寻找重复文件

Given a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of duplicate files in the file system in terms of their paths.

A group of duplicate files consists of at least two files that have exactly the same content.

A single directory info string in the input list has the following format:

"root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content)"

It means there are n files (f1.txtf2.txt ... fn.txt with content f1_contentf2_content ... fn_content, respectively) in directory root/d1/d2/.../dm. Note that n >= 1 and m >= 0. If m = 0, it means the directory is just the root directory.

The output is a list of group of duplicate file paths. For each group, it contains all the file paths of the files that have the same content. A file path is a string that has the following format:

"directory_path/file_name.txt"

Example 1:

Input:
["root/a 1.txt(abcd) 2.txt(efgh)", "root/c 3.txt(abcd)", "root/c/d 4.txt(efgh)", "root 4.txt(efgh)"]
Output:
[["root/a/2.txt","root/c/d/4.txt","root/4.txt"],["root/a/1.txt","root/c/3.txt"]]

Note:

  1. No order is required for the final output.
  2. You may assume the directory name, file name and file content only has letters and digits, and the length of file content is in the range of [1,50].
  3. The number of files given is in the range of [1,20000].
  4. You may assume no files or directories share the same name in the same directory.
  5. You may assume each given directory info represents a unique directory. Directory path and file info are separated by a single blank space.

Follow-up beyond contest:

  1. Imagine you are given a real file system, how will you search files? DFS or BFS?
  2. If the file content is very large (GB level), how will you modify your solution?
  3. If you can only read the file by 1kb each time, how will you modify your solution?
  4. What is the time complexity of your modified solution? What is the most time-consuming part and memory consuming part of it? How to optimize?
  5. How to make sure the duplicated files you find are not false positive?

s

时间: 2024-08-04 14:39:31

[LeetCode] Find Duplicate File in System 在系统中寻找重复文件的相关文章

leetcode 609. 在系统中查找重复文件

目录 题目描述: 示例 1: 解法: 题目描述: 给定一个目录信息列表,包括目录路径,以及该目录中的所有包含内容的文件,您需要找到文件系统中的所有重复文件组的路径.一组重复的文件至少包括二个具有完全相同内容的文件. 输入列表中的单个目录信息字符串的格式如下: "root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content)" 这意味着有 n 个文件(f1.txt,?f2.txt?...?fn.

609. Find Duplicate File in System

寻找重复文件的路径集合 /* 没有什么特别的技巧,就是用map存储相同内容的路径,核心就是getOrDefault()方法 注意步骤,想清楚思路 */ //记录结果 Map<String,ArrayList> map = new HashMap<>(); for (String path : paths) { //把根路径和各个文件分开 String[] files = path.split(" "); //遍历每个文件,有两个任务,一是存下改文件内容,二是把该

Linux系统中三类重要文件的作用与区别

文章来源 | IT笔录 Linux系统中,有三种文件类型出现的非常频繁,那就是profile.bash_profile.bashrc文件. 因为名称的缘故,很多人会把这三类文件的作用记混,因此我们今天就来详细盘点一下这三类文件的作用及区别. 1. profile文件 1.1 profile文件的作用 profile(/etc/profile),用于设置系统级的环境变量和启动程序,在这个文件下配置会对所有用户生效. 当用户登录(login)时,文件会被执行,并从/etc/profile.d目录的配

leetcode——Longest Substring Without Repeating Characters 求链表中无重复字符的最大字串长度(AC)

mnesia在频繁操作数据的过程可能会报错:** WARNING ** Mnesia is overloaded: {dump_log, write_threshold},可以看出,mnesia应该是过载了.这个警告在mnesia dump操作会发生这个问题,表类型为disc_only_copies .disc_copies都可能会发生. 如何重现这个问题,例子的场景是多个进程同时在不断地mnesia:dirty_write/2 mnesia过载分析 1.抛出警告是在mnesia 增加dump

609. Find Duplicate File in System(LeetCode)

Given a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of duplicate files in the file system in terms of their paths. A group of duplicate files consists of at l

linux 系统中的特殊文件

特殊文件是UNIX系统中最具特色的文件特性之一.特殊文件也称设备文件.提供用户访问外部设备,而不必知道各种设备的具体操作.UNIX利用特殊文件作为用户与设备文件的接口,使用户能像访问普通文件那样访问特殊文件.      特殊文件不包含任何数据,她只是提供了一种机制,即在文件系统中建立物理设备与文件名之间的映射.特殊文件利用mknod或系统调用创建,且必须提供相关的驱动程序,并集成到系统内核中.否则即使创建了特殊文件,也无法访问相应的设备.     mknod special   type  [

fastboot:刷系统中各个img文件

http://blog.163.com/zheng_he_xiang/blog/static/18650532620134305221222/ Android系统adb刷机 作者:郑鹤翔 在android的各个可用软件中,adb,fastboot是最常用的一种,作为开发人员, 我们需要经常的进行内核,系统代码等的修改,假如每一次修改,我们就要烧写一遍所有的img文件, 那样不就很烦躁~~~ 当然,在这方面google公司早就给了我们一个很好的方法!!! adb 和 fastboot软件!! 常用

关于win7系统中所有exe文件都被以word方式打开的解决方法

手残一刻,电脑桌面所有的软件快捷方式都变成了word的打开方式,鼠标右键选中某exe文件也没打开方式那个选项, 第一次尝试: 在控制面板——默认程序中修改默认打开方式,但是没有找到解决方法 第二次尝试: 万能的重启,你会发现,并没有卵用的…… 第三次尝试: 使用ctrl+alt+delete调出任务管理器,不要妄图使用在任务栏——右键——打开任务管理器,也同样只会是word方式打开,不停的报错,你想要关都关不掉,所以不用理会他,只管使用任务管理器,看到帖子上有人说:“结束掉explorer这个任

【转】Android系统中的.apk文件和dex文件

1. *.apk文件 APK是Android Package的缩写,即Android安装包.通过将APK文件直接传到Android模拟器或Android手机中执行即可安装. 使用Android打包工具(aapt)将DEX文件,资源文件以及AndroidManifest.xml文件组合成一个应用程序包(APK).Dex是Dalvik VM executes的全称,即Android Dalvik执行程序. META-INF\ Jar文件 res\ 存放资源文件 AndroidManifest.xml