[프로그래머스 | C# | Lv.0] 조건에 맞게 수열 변환하기 1

728x90

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

 

📝 나의 풀이

using System;

public class Solution {
    public int[] solution(int[] arr) {
        int[] answer = new int[arr.Length];
        
        for (int i = 0; i < answer.Length; i++) {
            if (arr[i] < 50 && arr[i] % 2 != 0) {
                answer[i] = arr[i] * 2;
            } else if (arr[i] >= 50 && arr[i] % 2 == 0) {
                answer[i] = arr[i] / 2;
            } else {
                answer[i] = arr[i];
            }
        }
        return answer;
    }
}
728x90