1. tina79515

    Posted

    tina79515
Changes in title
+Leetcode #609: Find Duplicate File in System
Changes in tags
Changes in body
Source | HTML | Preview
@@ -0,0 +1,35 @@
+```swift
+func findDuplicate(_ paths: [String]) -> [[String]] {
+ var dict = [String: [String]]()
+ for path in paths {
+ let components = path.components(separatedBy: " ")
+ for i in stride(from: 1, to: components.count, by: 1) {
+ var file = components[0] + "/"
+ var str = Array(components[i])
+ var index = 0
+ while str[index] != "(" {
+ file += "\(str[index])"
+ index += 1
+ }
+ index += 1
+ var content = ""
+ while str[index] != ")" {
+ content += "\(str[index])"
+ index += 1
+ }
+ if let value = dict[content] {
+ dict[content] = value + [file]
+ } else {
+ dict[content] = [file]
+ }
+ }
+ }
+ var answer = [[String]]()
+ for key in dict.keys {
+ if dict[key]!.count != 1 {
+ answer.append(dict[key]!)
+ }
+ }
+ return answer
+}
+```