Skip to content

Commit 7fef774

Browse files
authored
[20251106] PGM / LV2 / 롤 케이크 자르기 / 이인희
1 parent ef4e10d commit 7fef774

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(int[] toppings) {
6+
int answer=0;
7+
HashMap<Integer, Integer> r = new HashMap<>();
8+
for(int topping: toppings){
9+
if(!r.containsKey(topping)){
10+
r.put(topping, 0);
11+
}
12+
r.put(topping, r.get(topping)+1);
13+
}
14+
HashMap<Integer, Integer> l = new HashMap<>();
15+
for(int topping: toppings){
16+
if(!l.containsKey(topping)){
17+
l.put(topping, 0);
18+
}
19+
l.put(topping, l.get(topping)+1);
20+
r.put(topping, r.get(topping)-1);
21+
if(r.get(topping) == 0)
22+
r.remove(topping);
23+
if(l.size() == r.size())
24+
answer++;
25+
}
26+
return answer;
27+
}
28+
29+
}
30+
```

0 commit comments

Comments
 (0)