From adf5cef128fff11c9e5b5c8ab04941d2e9f089b5 Mon Sep 17 00:00:00 2001 From: Sang Yu Lee Date: Fri, 6 Feb 2026 01:48:10 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=AC=EB=9F=AC=EB=B6=84=20=EB=8D=95?= =?UTF-8?q?=EB=B6=84=EC=9E=85=EB=8B=88=EB=8B=A4=20=ED=81=AC=EC=95=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Liv.swift" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\211\264\354\212\244\355\201\264\353\237\254\354\212\244\355\204\260\353\247\201/Liv.swift" diff --git "a/WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\211\264\354\212\244\355\201\264\353\237\254\354\212\244\355\204\260\353\247\201/Liv.swift" "b/WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\211\264\354\212\244\355\201\264\353\237\254\354\212\244\355\204\260\353\247\201/Liv.swift" new file mode 100644 index 0000000..679474e --- /dev/null +++ "b/WEEK03/\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244_\353\211\264\354\212\244\355\201\264\353\237\254\354\212\244\355\204\260\353\247\201/Liv.swift" @@ -0,0 +1,34 @@ +// 프로그래머스 - 뉴스 클러스터링 + +func solution(_ str1: String, _ str2: String) -> Int { + var arr1: [String] = toSplit(str1.lowercased()) + var arr2: [String] = toSplit(str2.lowercased()) + + var intersection: Int = 0 + + if arr1.isEmpty, arr2.isEmpty { return 65536 } + + for item in arr1 { + if let idx = arr2.firstIndex(of: item) { + intersection += 1 + arr2.remove(at: idx) + } + } + + let union = arr1.count + arr2.count + return intersection * 65536 / union +} + +func toSplit(_ str: String) -> [String] { + var string = str + var result: [String] = [] + while !string.isEmpty { + var item: String = String(string.prefix(2)) + item.removeAll { !$0.isLetter } + if !item.isEmpty, item.count == 2 { + result.append(item) + } + string.removeFirst() + } + return result +}