웅재의 코딩세상

[프로그래머스] 홀수 vs 짝수 본문

코딩테스트/프로그래머스 - LV 0

[프로그래머스] 홀수 vs 짝수

웅드 2024. 1. 29. 18:06

 

 

  • 풀이
#include <string>
#include <vector>

using namespace std;

int solution(vector<int> num_list) {
    int answer[2];
    for(int i=0; i<num_list.size(); i++){
        if((i+1)%2 == 0) answer[0] += num_list[i];
        else answer[1] += num_list[i];
    }
    return answer[0] < answer[1] ? answer[1] : answer[0];
}
반응형