We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5ce8805 commit d5ecd86Copy full SHA for d5ecd86
Week12/폰켓몬/jiyoon.java
@@ -1,4 +1,21 @@
1
package Week12.폰켓몬;
2
+import java.util.*;
3
4
public class jiyoon {
5
+ class Solution {
6
+ public int solution(int[] nums) {
7
+ int answer = 0;
8
+
9
+ // 폰켓몬의 종류와 마리 수를 저장할 HashMap
10
+ HashMap<Integer, Integer> map = new HashMap<>(); // Key : 종류, Value : 마리 수
11
+ for (int i : nums) {
12
+ map.put(i, map.getOrDefault(i, 0) + 1);
13
+ }
14
15
+ // map.size()가 폰켓몬의 n마리 수 / 2보다 크다면 총 마리수의 절반 반환, 아니라면 map 크기 반환
16
+ answer = map.size() >= nums.length / 2 ? nums.length / 2 : map.size();
17
18
+ return answer;
19
20
21
}
0 commit comments