https://programmers.co.kr/learn/courses/30/lessons/12906
import java.util.*;
public class Solution {
public int[] solution(int []arr) {
int[] answer = {};
// 값을 담을 stack 생성
Stack<Integer> stack = new Stack<>();
for (int x: arr) {
// 스택이 비어있으면 그대로 넣어준다.
if (stack.isEmpty()) {
stack.add(x);
} else {
// 스택의 제일 위에 값이랑 현재 값이 다를 때에만 넣어준다.(중복 방지)
if (stack.peek() != x) {
stack.add(x);
}
}
}
// stream으로 int형 array로 변환시켜준다.
return stack.stream().mapToInt(Integer::intValue).toArray();
}
}