상세 컨텐츠

본문 제목

n 번째 원소까지

코딩테스트/C#

by MJ_119 2024. 6. 17. 00:23

본문

문제 설명

정수 리스트 num_list와 정수 n이 주어질 때, num_list의 첫 번째 원소부터 n 번째 원소까지의 모든 원소를 담은 리스트를 return하도록 solution 함수를 완성해주세요.


제한사항
  • 2 ≤ num_list의 길이 ≤ 30
  • 1 ≤ num_list의 원소 ≤ 9
  • 1 ≤ n  num_list의 길이 ___
입출력 예

 

using System;

public class Solution {
    public int[] solution(int[] num_list, int n) {
        int[] answer = new int[n];
        
        for (int i = 0; i < n; i++)
        {
            answer[i] = num_list[i];
        }
        
        return answer;
    }
}

'코딩테스트 > C#' 카테고리의 다른 글

n보다 커질 때까지 더하기  (0) 2024.06.17
n개 간격의 원소들  (0) 2024.06.17
5명씩  (0) 2024.06.16
홀수 vs 짝수  (1) 2024.06.16
n 번째 원소부터  (0) 2024.06.16

관련글 더보기