forked from GreatAlgorithm-Study/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDH_132265.java
More file actions
32 lines (26 loc) · 741 Bytes
/
DH_132265.java
File metadata and controls
32 lines (26 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
롤케이크_자르기
*/
class DH_132265 {
public int solution(int[] topping) {
int length = topping.length;
int toppingType = 0, answer = 0;
int cnt[] = new int[10_001];
for(int i = 0; i < length; i++) {
if(cnt[topping[i]] == 0) toppingType++;
cnt[topping[i]]++;
}
int cntA = 0;
boolean check[] = new boolean[10_001];
for(int i = 0; i < length; i++) {
if(!check[topping[i]]) {
cntA++;
check[topping[i]] = true;
}
cnt[topping[i]]--;
if(cnt[topping[i]] == 0) toppingType--;
if(cntA == toppingType) answer++;
}
return answer;
}
}