Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
25 lines (22 loc) · 803 Bytes

File metadata and controls

25 lines (22 loc) · 803 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package ch11;
import java.util.HashMap;
import java.util.Map;
// 해시 > 완주하지 못한 선수
public class P34_1 {
public String solution(String[] participant, String[] completion) {
Map<String, Integer> m = new HashMap<>();
// 참여 선수 이름, 동명이인인 경우 +1 해시맵 삽입
for (String p : participant)
m.put(p, m.getOrDefault(p, 0) + 1);
// 완주 선수 이름 제거
for (String c : completion) {
int left = m.get(c);
if (left == 1) // 하나만 있는 경우 키 자체를 삭제
m.remove(c);
else
m.put(c, left - 1);
}
// 남아 있는 유일한 키(이름) 리턴
return m.entrySet().iterator().next().getKey();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.