From 169d3e6aa7b0e10592f461ba72feca4df2bcf750 Mon Sep 17 00:00:00 2001 From: rl544 <111494264+rl544@users.noreply.github.com> Date: Fri, 16 Dec 2022 20:42:48 +0900 Subject: [PATCH] =?UTF-8?q?uploaded=20at=202022.=2012.=2016.=20=EC=98=A4?= =?UTF-8?q?=ED=9B=84=208:42:47?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- programmers/폰켓몬/solution.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 programmers/폰켓몬/solution.java diff --git a/programmers/폰켓몬/solution.java b/programmers/폰켓몬/solution.java new file mode 100644 index 0000000..33e6026 --- /dev/null +++ b/programmers/폰켓몬/solution.java @@ -0,0 +1,16 @@ +// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/1845 + +import java.util.HashMap; +class Solution { + public int solution(int[] nums) { + int answer = 0; + HashMap hash = new HashMap<>(); + for(int a : nums){ + hash.put(a,hash.getOrDefault(a,0)+1); + } + for(Integer b : hash.keySet()){ + answer += 1; + } + return (answer > nums.length/2) ? nums.length/2 : answer; + } +} \ No newline at end of file