-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();
}
}
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
[프로그래머스/Java] 크기가 작은 부분 문자열 (0) | 2025.02.25 |
---|---|
[프로그래머스/Java] 최대공약수와 최소공배수 (0) | 2025.02.25 |
[프로그래머스/Java] 직사각형 별찍기 (0) | 2025.02.25 |
[프로그래머스/Java] K번째수 (0) | 2025.02.25 |
[프로그래머스/Java] 행렬의 덧셈 (0) | 2025.02.24 |