[프로그래머스 | C# | Lv.0] n개 간격의 원소들

728x90

 

https://school.programmers.co.kr/learn/courses/30/lessons/181888

 

 

📝 나의 풀이

using System;

public class Solution {
    public int[] solution(int[] num_list, int n) {
        int[] answer;
        
        if(num_list.Length%n==0){
         answer = new int[num_list.Length/n];   
        } else {
          answer = new int[(num_list.Length/n)+1];  
        }

        int index =0;
        for(int i=0;i<num_list.Length; ){
            answer[index] = num_list[i];
            index++;
            i = i+n;
        }
        return answer;
    }
}
728x90