From fa90c2e3e57333476f2971ad5c0b22fad36041fe Mon Sep 17 00:00:00 2001 From: Hoyoung Jung Date: Fri, 7 Feb 2020 08:58:02 +0900 Subject: [PATCH] =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98=EB=A8=B8?= =?UTF-8?q?=EC=8A=A4=20=EC=99=84=EC=A3=BC=ED=95=98=EC=A7=80=20=EB=AA=BB?= =?UTF-8?q?=ED=95=9C=20=EC=84=A0=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 스트림으로 풀었다가 느려서 그냥 이터레이션으로 바꿈 분류: 해시 난이도: 2점 --- .../honux77/programmers-42576-Solution.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 200206/honux77/programmers-42576-Solution.java diff --git a/200206/honux77/programmers-42576-Solution.java b/200206/honux77/programmers-42576-Solution.java new file mode 100644 index 0000000..4840eba --- /dev/null +++ b/200206/honux77/programmers-42576-Solution.java @@ -0,0 +1,32 @@ +//프로그래머스 완주하지 못한 선수 + +import java.util.HashMap; + +public class Solution { + + public String solution(String[] participant, String[] completion) { + HashMap cmap = new HashMap<>(); + + for (String s: completion) { + Integer n = cmap.get(s); + if (n == null) { + cmap.put(s, 1); + } + else { + n++; + cmap.put(s, n); + } + } + + for (String s: participant) { + Integer n = cmap.get(s); + if(n == null || n == 0) { + return s; + } else { + n--; + cmap.put(s, n); + } + }; + return "Me"; + } +} \ No newline at end of file