웅재의 코딩세상

[프로그래머스] 길이에 따른 연산 본문

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

[프로그래머스] 길이에 따른 연산

웅드 2024. 1. 29. 17:52

 

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

using namespace std;

int solution(vector<int> num_list) {
    int answer = 0;
    if(num_list.size() >= 11) answer = accumulate(num_list.begin(), num_list.end(),0);
    else{
        answer =1;
        for(int i=0; i<num_list.size(); i++){
            answer *= num_list[i];
        }
    }
    return answer;
}
반응형