From da9c7ab4758718031de72073171f674d5eeaf9d1 Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Fri, 7 Feb 2020 10:05:09 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98?= =?UTF-8?q?=EB=A8=B8=EC=8A=A4=20=EB=8B=A4=EC=8B=9C=20=ED=92=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HashMap의 getOrDefault(k, v)를 써서 약간 깔끔해졌다. --- .../honux77/programmers-42576-Solution.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 200207/honux77/programmers-42576-Solution.java 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 From 34bd0d66840b9d7a3b09b7ae2ff6a3b55f57ae68 Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Fri, 7 Feb 2020 22:58:59 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EC=99=84=EC=A3=BC=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EB=AA=BB=ED=95=9C=20=EC=84=A0=EC=88=98=20-=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=EB=A1=9C=20=ED=92=80=EC=97=88=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 현욱이가 해시 쓰지 말라고 해서 정렬로 풀었음. --- .../honux77/programmers-42576-Solution-2.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 200207/honux77/programmers-42576-Solution-2.java 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