프로그래머스 - 순서 바꾸기

youngkyu MIn·2023년 9월 7일

문제링크 - 순서 바꾸기

class Solution {
    public int[] solution(int[] num_list, int n) {

        int[] answer = new int[num_list.length];
        int j = 0;

        for (int i = 0; i < num_list.length; i++) {

            if(n+i>=num_list.length) {
                answer[i] = num_list[j];
                j++;
            } else {
                answer[i] = num_list[n + i];
            }


        return answer;
    }
}
profile
한 줄 소개

0개의 댓글