We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1b48663 commit ab76a62Copy full SHA for ab76a62
2025-08-27/김태민/프로그래머스_롤케이크자르기.java
@@ -0,0 +1,26 @@
1
+import java.util.*;
2
+class Solution {
3
+ public int solution(int[] topping) {
4
+ int answer = 0;
5
+ Map<Integer,Integer> map = new HashMap<>();
6
+ Set<Integer> set = new HashSet<>();
7
+ for (int i = 0; i < topping.length;i++) {
8
+ map.put(topping[i], map.getOrDefault(topping[i],0) + 1);
9
+ }
10
+
11
+ for (int i = 0; i < topping.length - 1; i++) {
12
+ set.add(topping[i]);
13
14
+ map.put(topping[i], map.get(topping[i]) - 1);
15
16
+ if (map.get(topping[i]) == 0) {
17
+ map.remove(topping[i]);
18
19
+ if (set.size() == map.size()) {
20
+ answer++;
21
22
23
24
+ return answer;
25
26
+}
0 commit comments