문제 설명
해결과정
Solution.java
import java.util.*;
class Solution {
public int solution(int[] topping) {
int[] front = new int [topping.length];
int[] rear = new int [topping.length];
int answer = 0;
Set<Integer> set = new HashSet<>();
for(int i = 0; i < topping.length; i++) {
set.add(topping[i]);
front[i] = set.size();
}
set.clear();
for(int i = topping.length-1; 0 <= i ; i--) {
set.add(topping[i]);
rear[i] = set.size();
}
set.clear();
for(int i = 0; i < front.length-1; i++) {
if(front[i] == rear[i+1]) {
answer++;
}
}
return answer;
}
}
Java
복사