코딩테스트/[C#] 프로그래머스

[프로그래머스 | C# | Lv.0] 홀수 vs 짝수

냠냠쿠 2023. 9. 4. 19:53
728x90

 

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

 

 

📝 나의 풀이

using System;

public class Solution {
    public int solution(int[] num_list) {
        int answer = 0;
        int a = 0;
        int b = 0;
        
        for(int i=0; i<num_list.Length; i++){
            if(i%2!=0){
                a +=num_list[i];
            } else {
                b +=num_list[i];
            }
        }
        
        answer = a<b? b: a;
        
        return answer;
    }
}
728x90