Skip to content

Commit f362506

Browse files
committed
feat: resolved
1 parent d3f0ef2 commit f362506

File tree

1 file changed

+34
-1
lines changed
  • find_duplicate_file_in_system/src

1 file changed

+34
-1
lines changed

find_duplicate_file_in_system/src/lib.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
1+
use std::collections::HashMap;
2+
13
pub struct Solution {}
24

35
impl Solution {
6+
fn parse_path(path: &str) -> Vec<(String, String)> {
7+
let mut root = "";
8+
let mut result = vec![];
9+
for (i, s) in path.split(' ').enumerate() {
10+
if i == 0 {
11+
root = s;
12+
} else {
13+
let left = s.find("(").unwrap();
14+
result.push((
15+
format!("{}/{}", root, &s[..left]),
16+
s[left + 1..s.len() - 1].to_string(),
17+
))
18+
}
19+
}
20+
result
21+
}
22+
423
pub fn find_duplicate(paths: Vec<String>) -> Vec<Vec<String>> {
5-
vec![vec![]]
24+
let mut map = HashMap::new();
25+
for path in paths.iter() {
26+
for (p, content) in Self::parse_path(path) {
27+
match map.get_mut(&content) {
28+
None => {
29+
map.insert(content, vec![p]);
30+
}
31+
Some(v) => v.push(p),
32+
}
33+
}
34+
}
35+
map.iter()
36+
.filter(|(_, v)| v.len() > 1)
37+
.map(|(_, v)| v.clone())
38+
.collect::<Vec<Vec<String>>>()
639
}
740
}
841

0 commit comments

Comments
 (0)