웅재의 코딩세상
[프로그래머스] 빈 배열에 추가, 삭제하기 본문
- 풀이
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> arr, vector<bool> flag) {
vector<int> answer;
for(int i=0; i<flag.size(); i++){
if(flag[i]){
for(int j=0; j<arr[i]*2; j++){
answer.push_back(arr[i]);
}
}
else{
for(int j=0; j<arr[i]; j++){
answer.pop_back();
}
}
}
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 0' 카테고리의 다른 글
[프로그래머스] 문자열 묶기 (0) | 2024.02.01 |
---|---|
[프로그래머스] 세 개의 구분자 (0) | 2024.02.01 |
[프로그래머스] 1로 만들기 (0) | 2024.02.01 |
[프로그래머스] 문자열 잘라서 정렬하기 (0) | 2024.02.01 |
[프로그래머스] 왼쪽 오른쪽 (0) | 2024.02.01 |