From 6a718b3ca013fb4e87a4a8792649492f1f4aa481 Mon Sep 17 00:00:00 2001 From: MinwooJe <59834326+MinwooJe@users.noreply.github.com> Date: Sun, 8 Feb 2026 13:45:19 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A7=80=EC=A7=80=EC=A7=80=EC=A7=80=EA=B0=81?= =?UTF-8?q?=E3=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JSON.swift" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_[1\354\260\250] \353\211\264\354\212\244 \355\201\264\353\237\254\354\212\244\355\204\260\353\247\201/JSON.swift" diff --git "a/WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_[1\354\260\250] \353\211\264\354\212\244 \355\201\264\353\237\254\354\212\244\355\204\260\353\247\201/JSON.swift" "b/WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_[1\354\260\250] \353\211\264\354\212\244 \355\201\264\353\237\254\354\212\244\355\204\260\353\247\201/JSON.swift" new file mode 100644 index 0000000..dde8b7d --- /dev/null +++ "b/WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_[1\354\260\250] \353\211\264\354\212\244 \355\201\264\353\237\254\354\212\244\355\204\260\353\247\201/JSON.swift" @@ -0,0 +1,37 @@ +func solution(_ str1:String, _ str2:String) -> Int { + var result = 65536 + let (lhs, rhs) = (parse(str1), parse(str2)) + + let intersection = getIntersection(lhs, rhs) + let union = lhs.values.reduce(0, +) + rhs.values.reduce(0, +) - intersection + + guard union != 0 else { return 65536 } + + result = Int(Double(intersection) / Double(union) * 65536) + + return result +} + +func getIntersection(_ lhs: [String: Int], _ rhs: [String: Int]) -> Int { + var result = 0 + + for word in lhs.keys { + result += min(lhs[word, default: 0], rhs[word, default: 0]) + } + + return result +} + +func parse(_ str: String) -> [String: Int] { + var result = [String: Int]() + let arr = Array(str) + + for i in 0..