-
Notifications
You must be signed in to change notification settings - Fork 0
뉴스 클러스터링 #36
New issue
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @MinwooJe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 PR은 프로그래머스 레벨 2 문제인 "뉴스 클러스터링"을 해결하기 위한 Swift 코드를 추가합니다. 이 변경사항은 주어진 두 문자열의 유사도를 측정하는 알고리즘을 구현하며, 특히 문자열을 두 글자 단위의 다중집합으로 처리하고 이들의 교집합과 합집합을 활용하여 자카드 유사도 값을 계산합니다. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
전반적으로 뉴스 클러스터링 문제의 요구사항을 잘 이해하고 정확하게 구현하셨습니다. 코드가 명확하고 각 함수의 역할이 잘 분리되어 있습니다. 몇 가지 개선점을 제안드립니다. solution 함수에서 불필요한 가변 변수를 제거하고, getIntersection 함수를 reduce를 사용하여 더 간결하게 만들 수 있습니다. 또한 parse 함수에서 lowercased() 호출을 최적화하여 성능을 개선할 여지가 있습니다. 자세한 내용은 각 코드 라인에 남긴 주석을 참고해주세요.
| result = Int(Double(intersection) / Double(union) * 65536) | ||
|
|
||
| return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result 변수에 값을 할당한 후 바로 반환하는 대신, 계산된 값을 직접 반환하여 코드를 간결하게 만들 수 있습니다. 이 변경으로 인해 2행의 var result = 65536 선언이 불필요해지므로 함께 제거하는 것이 좋습니다. Swift에서는 불필요한 가변 상태를 줄이는 것이 권장됩니다.
| result = Int(Double(intersection) / Double(union) * 65536) | |
| return result | |
| return Int(Double(intersection) / Double(union) * 65536) |
| var result = 0 | ||
|
|
||
| for word in lhs.keys { | ||
| result += min(lhs[word, default: 0], rhs[word, default: 0]) | ||
| } | ||
|
|
||
| return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| var result = [String: Int]() | ||
| let arr = Array(str) | ||
|
|
||
| for i in 0..<str.count - 1 { | ||
| guard arr[i].isLetter && arr[i + 1].isLetter else { continue } | ||
|
|
||
| let word = String(arr[i]) + String(arr[i + 1]) | ||
| result[word.lowercased(), default: 0] += 1 | ||
| } | ||
|
|
||
| return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parse 함수 내에서 루프가 반복될 때마다 lowercased()가 호출되고 있습니다. 입력 문자열을 루프 시작 전에 한 번만 소문자로 변환하면 성능을 개선할 수 있습니다. 또한, 두 문자를 합쳐 문자열을 만들 때 String의 이니셜라이저에 배열 슬라이스를 전달하는 것이 문자열 덧셈보다 약간 더 효율적입니다.
var result = [String: Int]()
let arr = Array(str.lowercased())
for i in 0..<(arr.count - 1) {
guard arr[i].isLetter && arr[i + 1].isLetter else { continue }
let word = String(arr[i...i+1])
result[word, default: 0] += 1
}
return result
🔗 문제 링크
✔️ 소요된 시간
40분
📚 새롭게 알게된 내용