Beakjoon&프로그래머스/Java

[프로그래머스/Java] 같은 숫자는 싫어

현장 2025. 2. 25. 17:22

-Code

import java.util.*;

public class Solution {
    public int[] solution(int []arr) {
        List<Integer> answer = new ArrayList<>();
        int now = -1;

        for (int n : arr) {
            if (now != n) {
                now = n;
                answer.add(n);
            }
        }

        return answer.stream().mapToInt(Integer::intValue).toArray();
    }
}