week2/nonani#12
Open
nonani wants to merge 4 commits into
Open
Conversation
nonani
marked this pull request as ready for review
July 18, 2026 12:34
Vryez11
approved these changes
Jul 19, 2026
| int cost = nextNode[1]; | ||
| if (visited[next]) | ||
| continue; | ||
| pq.add(new int[]{next, cost}); |
Contributor
There was a problem hiding this comment.
처음에 제가 느낀 생각은 graph로 초기화하는 것이 costs의 전체 길이라면 그냥,
costs[2]로 Arraysort() 한 다음에 그냥 간선의 개수가 n - 1 이 될 때까지 visited한게 더 좋지 않을까 ? 생각했었던 것 같습니다!
뭔가 임의의 시작점에서 정해진 목표로 가는데 이용하면 최적의 효율로 찾을 수 있겠다?라고 생각이 드는데 모든 점이 연결되어야 하는 문제 상황에서 graph로 초기화해야 하나? 라는 생각입니다 ㅋㅎㅋㅎㅋ
사실 제가 틀릴 수도 있어서 아래는 두 알고리즘을 비교한, AI 답변 첨부 드립니다.
1. 입력 형태와 맞아요. costs가 이미 간선 리스트라서 정렬만 하면 끝. 프림은 인접 리스트를 따로 만들어야
해서 코드가 더 길어져요.
2. "연결되어 있는지 확인"이 곧 union-find예요. find(a) == find(b) 한 줄이 그 질문에 대한 답이라, 문제의
핵심 동작과 자료구조가 정확히 일치해요. 프림은 연결 여부를 visited로 간접 관리하죠.
3. 간선이 적은 그래프에 유리해요. 이 문제는 섬 100개 이하의 희소 그래프라 크루스칼 O(E log E)가
자연스러워요. 프림(인접행렬 O(V²) 버전)이 이기는 건 간선이 V²에 가까운 밀집 그래프일 때예요.
아.. 풀이 그건에 이미 알고 있었군요 죄송합니다 ......
Member
Author
There was a problem hiding this comment.
싸이클 체크하는게 귀찮아서 크루스칼은 조금 꺼려지더라구요 ㅋㅋㅋ
이 문제는 입력 데이터 형식부터 크루스칼 쓰라고 의도한 문제가 맞는 것 같습니다 🤣
| class Solution { | ||
| public int[] solution(String s) { | ||
|
|
||
| String[] subStrings = s.substring(2, s.length() - 2).split("\\},\\{"); |
twalla26
approved these changes
Jul 19, 2026
| for (String number : sub.split(",")) { | ||
| int value = Integer.parseInt(number); | ||
|
|
||
| if (visited.add(value)) { |
Contributor
There was a problem hiding this comment.
set.add() 반환값이 boolean 이군요! 새로운거 알아갑니다 👍 👍
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
✏️ 2주차
해결한 문제
해결하지 못한 문제