import java.util.*;
public class Solution {
public ArrayList<Integer> solution(int []arr) {
ArrayList<Integer> list = new ArrayList<>();
Stack<Integer> stack = new Stack<>();
stack.push(arr[0]);
for(int i=1; i<arr.length; i++){
if(arr[i-1] != arr[i]){
stack.push(arr[i]);
}
}
for(int i=0; i<stack.size(); i++){
list.add(stack.get(i));
}
return list;
}
}
'공부기록 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 폰켓몬 (0) | 2023.09.16 |
---|---|
[프로그래머스] 완주하지 못한 학생 (0) | 2023.09.14 |
[프로그래머스] 올바른 괄호 (0) | 2023.09.14 |
[프로그래머스] 행렬의 곱셈 (0) | 2023.09.03 |
[프로그래머스] 이상한 문자 만들기 (0) | 2023.09.03 |