반응형
https://school.programmers.co.kr/learn/courses/30/lessons/181895
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
답
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> arr, vector<vector<int>> intervals) {
vector<int> answer;
for(int i=0;i<intervals.size();i++){//첫번쨰
for(int j=intervals[i][0];j<=intervals[i][1];j++){//두번쨰
answer.push_back(arr[j]);
}
}
return answer;
}
vector answer을 새로 만들어준다.
intervals의 크기만큼 첫번째 for문을 만든다.(i)
intervals[i][0]부터 intervals[i][1]까지 for문을 만든다.(j)
answer에 arr[j]를 넣어준다.
끝
반응형
'c++ > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 글자 지우기(c++) (0) | 2023.12.25 |
---|---|
[프로그래머스] 세로 읽기(c++) (0) | 2023.12.25 |
[프로그래머스] 수열과 구간 쿼리 1(c++) (0) | 2023.12.25 |
[프로그래머스] 빈 배열에 추가, 삭제하기(c++) (0) | 2023.12.25 |
[프로그래머스] l로 만들기(c++) (0) | 2023.12.25 |