웅재의 코딩세상

[프로그래머스] 배열의 원소만큼 추가하기 본문

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

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

웅드 2024. 1. 25. 18:03

 

 

 

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

using namespace std;

vector<int> solution(vector<int> arr) {
    vector<int> answer;
    for(int i=0; i<arr.size(); i++){
        for(int j=0; j<arr[i]; j++){
            answer.push_back(arr[i]);
        }
    }
    return answer;
}
반응형