프로그래머스/Lv.0

[프로그래머스 C#] 짝수는 싫어요

suniverse 2023. 8. 4. 11:52

 

using System;
using System.Collections.Generic;

public class Solution {
    public int[] solution(int n) {
        List<int> list = new List<int>();
        for(int i = 1; i <= n; i++)
        {
            if(i % 2 == 1)
            {
                list.Add(i);
            }
        }
        
        int[] answer = new int[list.Count];
        for(int i = 0; i < list.Count; i++)
        {
            answer[i] = list[i];
        }
        return answer;
    }
}