import java.util.*;
public class Solution {
public int[] solution(int[] arr) {
Stack<Integer> stack = new Stack<Integer>();
for (int i = 0; i < arr.length; i++) {
if (stack.isEmpty()) {
stack.push(arr[i]);
} else if (arr[i] == (Integer) stack.peek()) {
continue;
} else {
stack.push(arr[i]);
}
}
int[] answer = new int[stack.size()];
int idx = stack.size() - 1;
while (!stack.isEmpty()) {
answer[idx] = stack.pop();
idx--;
}
return answer;
}
}
Stack<Integer>
https://school.programmers.co.kr/learn/courses/30/lessons/12910