Help us understand the problem. What is going on with this article?

Leetcode #609: Find Duplicate File in System

More than 1 year has passed since last update.
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
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした