https://school.programmers.co.kr/learn/courses/30/lessons/12906
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
연속적으로 값을 확인할 때 항상 첫번째 값, 마지막 값이 처리 되는지 확인해야 한다
import java.util.*;
public class Solution {
public int[] solution(int []arr) {
List<Integer> ans = new ArrayList<>();
int i = 0, j = 0;
ans.add(arr[0]);
while(j < arr.length) {
if(arr[i] == arr[j]) {
j += 1;
}else {
i = j;
ans.add(arr[i]);
}
}
int[] answer = ans.stream().mapToInt(Integer::intValue).toArray();
return answer;
}
}
[프로그래머스] 연속 부분 수열 합의 개수 (0) | 2024.12.16 |
---|---|
[프로그래머스] H-Index (0) | 2024.12.12 |
[프로그래머스] [1차] 캐시 (0) | 2024.12.12 |
[프로그래머스] [1차] 비밀지도 (0) | 2024.12.10 |
[프로그래머스] n^2배열 자르기 (0) | 2024.12.10 |