-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy path0609-FindDuplicateFileInSystem.cs
40 lines (35 loc) · 1.31 KB
/
0609-FindDuplicateFileInSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//-----------------------------------------------------------------------------
// Runtime: 312ms
// Memory Usage: 49.8 MB
// Link: https://leetcode.com/submissions/detail/372006171/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _0609_FindDuplicateFileInSystem
{
public IList<IList<string>> FindDuplicate(string[] paths)
{
var map = new Dictionary<string, IList<string>>();
foreach (var path in paths)
{
var values = path.Split(' ');
var dir = values[0];
for (int i = 1; i < values.Length; i++)
{
var name_content = values[i].Split('(');
var name = name_content[0];
var content = name_content[1].Substring(0, name_content[1].Length - 1);
if (!map.ContainsKey(content))
map[content] = new List<string>();
map[content].Add($"{dir}/{name}");
}
}
var result = new List<IList<string>>();
foreach (var files in map.Values)
if (files.Count > 1)
result.Add(files);
return result;
}
}
}