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
}
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
00