Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 📌 문제 링크
(문제 링크 또는 문제 캡처본을 첨부해주세요.)


---

## 📝 문제 개요
-

---

## 🧩 풀이 과정 요약
-

---

## 😁 결과
(문제 해결 결과를 첨부해주세요.)
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/week01/Yoepee/BOJ_1000.java

This file was deleted.

50 changes: 50 additions & 0 deletions src/week01/Yoepee/PG_42576.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package week01.Yoepee;

import java.util.*;

public class PG_42576 {
public static String solution(String[] participant, String[] completion) {
String answer = "";
Arrays.sort(participant);
Arrays.sort(completion);
for(int i =0; i<participant.length; i++){
if (i == participant.length-1) return participant[i];
if (participant[i].equals(completion[i]) == false) {
return participant[i];
}
}
return answer;
}

public static String solution2(String[] participant, String[] completion) {
String answer = "";
Map<String, Integer> map = new HashMap<>();
for(int i =0; i<participant.length;i++){
Copy link
Collaborator

Choose a reason for hiding this comment

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

저는 예전에 getOrDefault를 써서 풀었는데,
merge 방식은 처음 봐서 배워갑니다!

Copy link
Collaborator

@jjuchan jjuchan Jul 8, 2025

Choose a reason for hiding this comment

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

이게 제 코드 였습니다.!!

// 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;
}
}

map.merge(participant[i], 1, (v1, v2) -> Math.max(v1,v2)+1);
}
for(int i =0; i<completion.length;i++){
map.merge(completion[i], 0, (v1, v2) -> v1-1);
}
for(int i =0; i<participant.length;i++){
if(map.get(participant[i]) == 1){
answer =participant[i];
break;
}
}

return answer;
}

public static void main(String[] args) {
// 정상 결과: "leo"
System.out.println(solution(new String[]{"leo", "kiki", "eden"}, new String[]{"eden", "kiki"}));
// 정상 결과: "vinko"
System.out.println(solution(new String[]{"marina", "josipa", "nikola", "vinko", "filipa"}, new String[]{"josipa", "filipa", "marina", "nikola"}));
// 정상 결과: "mislav"
System.out.println(solution(new String[]{"mislav", "stanko", "mislav", "ana"}, new String[]{"stanko", "ana", "mislav"}));
// 정상 결과: "b"
System.out.println(solution(new String[]{"a", "b", "a", "c", "d"}, new String[]{"a", "a", "c", "d"}));
// 정상 결과: "b"
System.out.println(solution(new String[]{"a", "a", "b", "a", "c", "d"}, new String[]{"a", "a", "a", "c", "d"}));
}
}