-> 자세한 내용 보러가기
import java.util.*;
public class Solution {
public int[] solution(int []arr) {
//스택 사용
Stack<Integer> stack = new Stack<>();
for(int num : arr){
if(stack.isEmpty() || stack.peek() != num){
stack.push(num);
}
}
int[] answer = new int[stack.size()];
for(int idx = stack.size()-1; idx >= 0; idx--){
answer[idx] = stack.pop();
}
return answer;
}
}