Problem Solving/Programmers
[Level 1] 같은 숫자는 싫어
kmkunk
2022. 3. 24. 14:10
import java.util.*;
public class Solution {
public int[] solution(int []arr) {
Stack<Integer> stack = new Stack<>();
for(int n : arr) {
if(!stack.isEmpty() && stack.peek()==n) { continue; }
stack.push(n);
}
int[] answer = new int[stack.size()];
for(int i=answer.length-1; i>=0; i--) { answer[i] = stack.pop(); }
return answer;
}
}