Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77f6990

Browse files
이지영: [PG] 롤케이크_자르기_240912
1 parent 21947d2 commit 77f6990

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int solution(int[] topping) {
5+
int answer = 0;
6+
Map<Integer, Integer> right = new HashMap<>();
7+
for(int t: topping){
8+
right.put(t, right.getOrDefault(t, 0)+1);
9+
}
10+
// System.out.println(right);
11+
12+
Map<Integer, Integer> left = new HashMap<>();
13+
for(int i=0; i<topping.length; i++){
14+
int t = topping[i];
15+
// left에 삽입
16+
left.put(t, left.getOrDefault(t, 0)+1);
17+
// right에서 제거
18+
right.put(t, right.get(t)-1);
19+
if(right.get(t) == 0){
20+
right.remove(t);
21+
}
22+
23+
if(left.keySet().size() == right.keySet().size()) answer++;
24+
}
25+
26+
return answer;
27+
}
28+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /