Conversation
jjuchan
reviewed
Jul 8, 2025
| public static String solution2(String[] participant, String[] completion) { | ||
| String answer = ""; | ||
| Map<String, Integer> map = new HashMap<>(); | ||
| for(int i =0; i<participant.length;i++){ |
Collaborator
There was a problem hiding this comment.
저는 예전에 getOrDefault를 써서 풀었는데,
merge 방식은 처음 봐서 배워갑니다!
Collaborator
There was a problem hiding this comment.
이게 제 코드 였습니다.!!
// getOrDefault를 사용해 기존 값이 없으면 0으로 초기화해 카운트를 누적합니다.
for (String p : participant) {
map.put(p, map.getOrDefault(p, 0) + 1);
}
// 완주자 목록을 돌며 참가 횟수를 1씩 차감합니다. 중복처리
for (String c : completion) {
map.put(c, map.get(c) - 1);
}
// map을 순회하며 값이 0이 아닌 key가 완주하지 못한 선수임을 찾습니다.
for (String key : map.keySet()) {
if (map.get(key) != 0) {
return key;
}
}
jjuchan
approved these changes
Jul 14, 2025
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.
📌 문제 링크
(문제 링크 또는 문제 캡처본을 첨부해주세요.)

프로그래머스 42576번 - 완주하지 못한 선수
📝 문제 개요
🧩 풀이 과정 요약
풀이 1: 정렬 후 비교
1.두 배열을 사전 순 정렬
2.앞에서부터 인덱스별로 비교
3.처음 불일치하는 사람 = 완주 못한 사람
4.모두 같으면 마지막 참가자가 미완주자
풀이 2: HashMap 활용 (이름별 인원 수)
😁 결과
(문제 해결 결과를 첨부해주세요.)
