Skip to content

Conversation

@MinwooJe
Copy link
Member

@MinwooJe MinwooJe commented Feb 8, 2026

🔗 문제 링크

✔️ 소요된 시간

40분

📚 새롭게 알게된 내용

@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • 새로운 파일 추가: WEEK03/프로그래머스_[1차] 뉴스 클러스터링/JSON.swift 경로에 뉴스 클러스터링 문제 해결을 위한 Swift 코드가 추가되었습니다.
  • 뉴스 클러스터링 알고리즘 구현: 두 문자열의 다중집합 교집합과 합집합을 계산하여 자카드 유사도(Jaccard similarity)를 구하는 solution 함수와, 문자열을 두 글자씩 끊어 다중집합으로 변환하는 parse 함수, 그리고 두 다중집합의 교집합 크기를 계산하는 getIntersection 함수가 구현되었습니다.

🧠 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
  • WEEK03/프로그래머스_[1차] 뉴스 클러스터링/JSON.swift
    • 뉴스 클러스터링 문제 해결을 위한 Swift 소스 코드가 추가되었습니다.
    • solution, getIntersection, parse 세 가지 함수로 구성되어 있습니다.
    • parse 함수는 입력 문자열에서 영문자로만 이루어진 두 글자 쌍(bigram)을 추출하고 소문자로 변환하여 각 쌍의 출현 횟수를 딕셔너리 형태로 반환합니다.
    • getIntersection 함수는 두 개의 다중집합(딕셔너리)을 받아 교집합의 크기를 계산합니다.
    • solution 함수는 parse와 getIntersection을 활용하여 두 문자열의 자카드 유사도를 계산하고, 65536을 곱한 정수 값을 반환합니다.
Activity
  • 현재까지 이 PR에 대한 코멘트나 리뷰 활동은 없습니다.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@MinwooJe MinwooJe removed the 문자열 label Feb 8, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a 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() 호출을 최적화하여 성능을 개선할 여지가 있습니다. 자세한 내용은 각 코드 라인에 남긴 주석을 참고해주세요.

Comment on lines +10 to +12
result = Int(Double(intersection) / Double(union) * 65536)

return result

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

result 변수에 값을 할당한 후 바로 반환하는 대신, 계산된 값을 직접 반환하여 코드를 간결하게 만들 수 있습니다. 이 변경으로 인해 2행의 var result = 65536 선언이 불필요해지므로 함께 제거하는 것이 좋습니다. Swift에서는 불필요한 가변 상태를 줄이는 것이 권장됩니다.

Suggested change
result = Int(Double(intersection) / Double(union) * 65536)
return result
return Int(Double(intersection) / Double(union) * 65536)

Comment on lines +16 to +22
var result = 0

for word in lhs.keys {
result += min(lhs[word, default: 0], rhs[word, default: 0])
}

return result

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

for 루프를 사용하여 합계를 계산하는 대신 reduce 고차 함수를 사용하면 코드를 더 간결하고 함수형 프로그래밍 스타일에 가깝게 작성할 수 있습니다.

    return lhs.keys.reduce(0) { result, word in
        result + min(lhs[word, default: 0], rhs[word, default: 0])
    }

Comment on lines +26 to +36
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant