-
Notifications
You must be signed in to change notification settings - Fork 0
[1차] 뉴스 클러스터링 #33
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
Open
dongglehada
wants to merge
1
commit into
main
Choose a base branch
from
raven
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[1차] 뉴스 클러스터링 #33
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| func solution(_ str1:String, _ str2:String) -> Int { | ||
|
|
||
| var str1 = makeWordList(str1) | ||
| var str2 = makeWordList(str2) | ||
| var intersection: Int = 0 | ||
| for key in str1.0.keys { | ||
| let num = min(str1.0[key] ?? 0, str2.0[key] ?? 0) | ||
| intersection += num | ||
| } | ||
| let union = str1.1 + str2.1 - intersection | ||
|
|
||
| if str1.1 == 0 && str2.1 == 0 { | ||
| return 65536 | ||
| } | ||
| return 65536 * intersection / union | ||
|
Comment on lines
+13
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| func makeWordList(_ str: String) -> ([String: Int], Int) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| var word: String = "" | ||
| var wordMap: [String: Int] = [:] | ||
| var count: Int = 0 | ||
| for s in str.lowercased() { | ||
| if !s.isLetter { | ||
| word = "" | ||
| continue | ||
| } | ||
| word += String(s) | ||
| if word.count == 2 { | ||
| wordMap[word, default: 0] += 1 | ||
| count += 1 | ||
| word = String(s) | ||
| } | ||
| } | ||
| return (wordMap, count) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
makeWordList함수에서 반환하는 튜플의 요소에 이름을 부여하면 코드의 가독성을 크게 향상시킬 수 있습니다. 또한,str1과str2매개변수를 섀도잉하는 대신, 튜플을 직접 구조 분해하여 명확한 변수 이름을 사용하는 것이 좋습니다.