Skip to content

Commit ab76a62

Browse files
authored
Create 프로그래머스_롤케이크자르기.java
1 parent 1b48663 commit ab76a62

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)