import java.util.*;
class Solution {
public class MarathonInfo {
String[] participant;
String[] completion;
String[] noCompletion;
public MarathonInfo(String[] participant, String[] completion) {
this.participant = participant;
this.completion = completion;
}
public void setNoCompletion(String[] noCompletion) {
this.noCompletion = noCompletion;
}
}
public String[] computeNoCompleInfo(MarathonInfo marathonInfo) {
HashMap<String, Integer> computeInfo = new HashMap<>();
for (String one : marathonInfo.participant) {
computeInfo.put(one, computeInfo.getOrDefault(one, 0) + 1);
}
for (String comple : marathonInfo.completion) {
computeInfo.put(comple, computeInfo.get(comple) - 1);
}
String[] gogo = computeInfo.entrySet().stream()
.filter(part -> part.getValue() != 0)
.map(tt -> tt.getKey())
.toArray(String[]::new);
return gogo.clone();
}
public String solution(String[] participant, String[] completion) {
String answer = "";
MarathonInfo marathonInfo = new MarathonInfo(participant, completion);
marathonInfo.setNoCompletion(computeNoCompleInfo(marathonInfo));
answer = marathonInfo.noCompletion[0];
return answer;
}
}
'알고리즘' 카테고리의 다른 글
프로그래머스 완주하지 못한선수 (튜닝) (0) | 2022.01.29 |
---|---|
프로그래머스 베스트앨범 (0) | 2022.01.28 |
프로그래머스 위장 (0) | 2022.01.27 |
백준 1644 소수의 연속합. (0) | 2019.04.24 |
[소수 알고리즘]에라스토테네스의 체. (0) | 2019.04.24 |