Skip to content

Commit d5ecd86

Browse files
committed
feat: 구현
1 parent 5ce8805 commit d5ecd86

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Week12/폰켓몬/jiyoon.java

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
package Week12.폰켓몬;
2+
import java.util.*;
23

34
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+
}
421
}

0 commit comments

Comments
 (0)