프로그래머스 - 짝수는 싫어요

parkkhee·2023년 2월 23일
0
class Solution {
    public int[] solution(int n) {
        int[] answer = new int[n%2!=0?n/2+1:n/2];
        int cnt=0;
        for(int i=1; i<n+1; i++){
            if(i%2 == 0){
                continue;
            }else{
                answer[cnt] = i;
                cnt++;
            }
            
        }
        
        return answer;
    }
}
profile
순우리말 백엔드 개발자

0개의 댓글