diff --git a/200207/honux77/programmers-42576-Solution-2.java b/200207/honux77/programmers-42576-Solution-2.java new file mode 100644 index 0000000..c1d7a59 --- /dev/null +++ b/200207/honux77/programmers-42576-Solution-2.java @@ -0,0 +1,18 @@ +// 정렬 사용해서 다시 풀었음 +import java.util.Arrays; + +public class Solution { + + public String solution(String[] participant, String[] completion) { + Arrays.sort(participant); + Arrays.sort(completion); + + int i; + for (i = 0; i < completion.length; i++) { + if (!participant[i].equals(completion[i])) { + return participant[i]; + } + } + return participant[i]; + } +} \ No newline at end of file diff --git a/200207/honux77/programmers-42576-Solution.java b/200207/honux77/programmers-42576-Solution.java new file mode 100644 index 0000000..e37d871 --- /dev/null +++ b/200207/honux77/programmers-42576-Solution.java @@ -0,0 +1,21 @@ +//프로그래머스 완주하지 못한 선수 + +import java.util.HashMap; + +public class Solution { + + public String solution(String[] participant, String[] completion) { + HashMap cmap = new HashMap<>(); + + for (String s: completion) { + cmap.put(s, cmap.getOrDefault(s, 0) + 1); + } + + for (String s: participant) { + int n = cmap.getOrDefault(s, 0); + if (n == 0) return s; + cmap.put(s, n - 1); + } + return "error"; + } +} \ No newline at end of file