From 9e3b9fbd866be99758ae4efa86ec6e49bc788fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=84=B1=ED=9B=88?= Date: Thu, 5 Feb 2026 10:29:37 +0900 Subject: [PATCH] =?UTF-8?q?=ED=95=98=ED=95=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Oliver.swift" | 42 +++++++++++++++++++ 1 file changed, 42 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/Oliver.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/Oliver.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/Oliver.swift" new file mode 100644 index 0000000..d2af389 --- /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/Oliver.swift" @@ -0,0 +1,42 @@ +func solution(_ str1: String, _ str2: String) -> Int { + let jac = jaccard(str1, str2) + return Int(jac * 65536) +} + +// 자카드 유사도 +func jaccard(_ s1: String, _ s2: String) -> Double { + let set1 = makeSet(s1) + var set2 = makeSet(s2) + + if set1.isEmpty && set2.isEmpty { return 1.0 } + + var intersection: [String] = [] + var unionCount: Int = 0 + + for element in set1 { + if let idx = set2.firstIndex(of: element) { + intersection.append(element) + set2.remove(at: idx) + } + } + + unionCount = set1.count + set2.count + return Double(intersection.count) / Double(unionCount) +} + +// 집합 만들기 +func makeSet(_ string: String) -> [String] { + let chars = Array(string.lowercased()) + var result: [String] = [] + + for i in 0..