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

[프로그래머스] n보다 커질 때까지 더하기

웅드 2024. 1. 25. 17:01

 

 

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

using namespace std;

int solution(vector<int> numbers, int n) {
    int answer = 0;
    for(int i=0; i< numbers.size(); i++){
        if(answer <= n) answer += numbers[i];
        else break;
    }
    return answer;
}
반응형