2022-12-17 18:45:02 +09:00
|
|
|
// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/12906#
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
public class Solution {
|
|
|
|
|
public int[] solution(int []arr) {
|
2022-12-17 18:48:07 +09:00
|
|
|
LinkedList<Integer> q = new LinkedList<Integer>();
|
2022-12-17 18:45:02 +09:00
|
|
|
for(int b : arr){
|
2022-12-17 18:48:07 +09:00
|
|
|
if(q.peekLast() != null && b == q.peekLast()) continue;
|
2022-12-17 18:45:12 +09:00
|
|
|
else q.add(b);
|
2022-12-17 18:45:02 +09:00
|
|
|
}//list 상태에서도 가능하지만 array가 수요이니 array로 변환합니다.
|
|
|
|
|
return q.stream().mapToInt(Integer::intValue).toArray();
|
|
|
|
|
}
|
|
|
|
|
}
|