Skip to content

Commit dca3e63

Browse files
committed
[level 1] Title: 완주하지 못한 선수, Time: 97.94 ms, Memory: 97.3 MB -BaekjoonHub
1 parent 52264df commit dca3e63

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# [level 1] 완주하지 못한 선수 - 42576
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/42576)
4+
5+
### 성능 요약
6+
7+
메모리: 97.3 MB, 시간: 97.94 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 해시
12+
13+
### 채점결과
14+
15+
정확성: 58.3<br/>효율성: 41.7<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2025년 07월 18일 22:26:58
20+
21+
### 문제 설명
22+
23+
<p>수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다.</p>
24+
25+
<p>마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수들의 이름이 담긴 배열 completion이 주어질 때, 완주하지 못한 선수의 이름을 return 하도록 solution 함수를 작성해주세요.</p>
26+
27+
<h5>제한사항</h5>
28+
29+
<ul>
30+
<li>마라톤 경기에 참여한 선수의 수는 1명 이상 100,000명 이하입니다.</li>
31+
<li>completion의 길이는 participant의 길이보다 1 작습니다.</li>
32+
<li>참가자의 이름은 1개 이상 20개 이하의 알파벳 소문자로 이루어져 있습니다.</li>
33+
<li>참가자 중에는 동명이인이 있을 수 있습니다.</li>
34+
</ul>
35+
36+
<h5>입출력 예</h5>
37+
<table class="table">
38+
<thead><tr>
39+
<th>participant</th>
40+
<th>completion</th>
41+
<th>return</th>
42+
</tr>
43+
</thead>
44+
<tbody><tr>
45+
<td>["leo", "kiki", "eden"]</td>
46+
<td>["eden", "kiki"]</td>
47+
<td>"leo"</td>
48+
</tr>
49+
<tr>
50+
<td>["marina", "josipa", "nikola", "vinko", "filipa"]</td>
51+
<td>["josipa", "filipa", "marina", "nikola"]</td>
52+
<td>"vinko"</td>
53+
</tr>
54+
<tr>
55+
<td>["mislav", "stanko", "mislav", "ana"]</td>
56+
<td>["stanko", "ana", "mislav"]</td>
57+
<td>"mislav"</td>
58+
</tr>
59+
</tbody>
60+
</table>
61+
<h5>입출력 예 설명</h5>
62+
63+
<p>예제 #1<br>
64+
"leo"는 참여자 명단에는 있지만, 완주자 명단에는 없기 때문에 완주하지 못했습니다.</p>
65+
66+
<p>예제 #2<br>
67+
"vinko"는 참여자 명단에는 있지만, 완주자 명단에는 없기 때문에 완주하지 못했습니다.</p>
68+
69+
<p>예제 #3<br>
70+
"mislav"는 참여자 명단에는 두 명이 있지만, 완주자 명단에는 한 명밖에 없기 때문에 한명은 완주하지 못했습니다.</p>
71+
72+
<hr>
73+
74+
<p>※ 공지 - 2023년 01월 25일 테스트케이스가 추가되었습니다.</p>
75+
76+
77+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public String solution(String[] participant, String[] completion) {
5+
String answer = "";
6+
HashMap<String, Integer> map = new HashMap<String, Integer>();
7+
for (int i = 0; i < participant.length; i++) {
8+
int value = 1;
9+
if (map.containsKey(participant[i])) {
10+
value = map.get(participant[i]) + 1;
11+
}
12+
map.put(participant[i], value);
13+
}
14+
for (int i = 0; i < completion.length; i++) {
15+
if (map.containsKey(completion[i])) {
16+
if (map.get(completion[i]) == 1) {
17+
map.remove(completion[i]);
18+
} else {
19+
map.put(completion[i], map.get(completion[i]) - 1);
20+
}
21+
}
22+
}
23+
24+
for (Map.Entry<String, Integer> entry : map.entrySet()) {
25+
answer = entry.getKey();
26+
}
27+
return answer;
28+
}
29+
}

0 commit comments

Comments
 (0)