프로그래머스 181861 배열의 원소만큼 추가하기

1 개요[ | ]

프로그래머스 181861 배열의 원소만큼 추가하기

2 C++[ | ]

#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> arr) {
    vector<int> answer;
    for(int el: arr) {
        answer.insert(answer.end(), el, el);
    }
    return answer;
}
#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> arr) {
    vector<int> answer;
    for(int el: arr) {
        for(int i=0; i<el; i++) {
            answer.emplace_back(el);
        }
    }
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}