[프로그래머스 | Lv.0] 짝수는 싫어요

이승민·2023년 8월 5일
0

프로그래머스

목록 보기
22/27

https://school.programmers.co.kr/learn/courses/30/lessons/120813?language=csharp

📝 나의 풀이

using System;

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

        int index =0;
        
        for(int i=1; i<=n; i++){   
            
            if(i%2!=0){
                answer[index] = i;
                index++;
            }
        }
        return answer;
    }
}

0개의 댓글

관련 채용 정보