We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💬 문제
[1차] 뉴스 클러스터링
💬 Idea
💬 풀이
func solution(str1:String, str2:String) -> Int { let str1MultipleArr: [String] = sliceArr(Array(str1).map{ String($0) }, "^[a-z]+$") let str2MultipleArr: [String] = sliceArr(Array(str2).map{ String($0) }, "^[a-z]+$") let key = Set(str1MultipleArr + str2MultipleArr) var intersection: [String] = [] var union: [String] = [] for k in key { let s1 = str1MultipleArr.filter{ $0 == k }.count let s2 = str2MultipleArr.filter{ $0 == k }.count // 교 if s1 != 0 && s2 != 0 { for _ in 0..<min(s1, s2) { intersection.append(k) } } // 합 for _ in 0..<max(s1, s2) { union.append(k) } } if intersection.count == 0 && union.count == 0 { return 65536 } else { return Int((Double(intersection.count) / Double(union.count) * 65536)) } } func sliceArr(_ str: [String], _ regex: String) -> [String] { var arr: [String] = [] for i in 0..<str.count - 1 { let s = str[i...i + 1].map{ String($0) }.joined().lowercased() if !s.allSatisfy({ $0.isLetter }) { continue } if s.range(of: regex, options: .regularExpression) == nil { continue } arr.append(s) } return arr }
💬 더 나은 방법?
s.allSatisfy({ $0.isLetter })
💬 알게된 문법
func getArrayAfterRegex(regex: String) -> [String] { do { let regex = try NSRegularExpression(pattern: regex) let results = regex.matches(in: self, range: NSRange(self.startIndex..., in: self)) return results.map { String(self[Range($0.range, in: self)!]) } } catch let error { print("invalid regex: \(error.localizedDescription)") return [] } }
[[Swift] Swift에서 정규표현식(Regular Expression)을 이용하기](https://eunjin3786.tistory.com/12)
The text was updated successfully, but these errors were encountered:
#114 - [1차] 뉴스 클러스터링 문제 풀이
7257a3d
hwangJi-dev
No branches or pull requests
💬 문제
[1차] 뉴스 클러스터링
💬 Idea
💬 풀이
💬 더 나은 방법?
💬 알게된 문법
[[Swift] Swift에서 정규표현식(Regular Expression)을 이용하기](https://eunjin3786.tistory.com/12)
The text was updated successfully, but these errors were encountered: