[프로그래머스]n개 간격의 원소들

박예림·2023년 5월 25일
0

코테

목록 보기
111/132

import java.util.*;
class Solution {
    public int[] solution(int[] num_list, int n) {
        List<Integer> integerList = new ArrayList<>();

        for (int i = 0; i < num_list.length; i++) {
            if (i%n==0){
                integerList.add(num_list[i]);
            }
        }

        int[] answer = integerList.stream()
                .mapToInt(Integer::intValue)
                .toArray();

        return answer;
    }
}
profile
응애 나 아기개발자

0개의 댓글