코딩테스트 연습 - n의 배수 고르기


#include <string>
#include <vector>
using namespace std;
vector<int> solution(int n, vector<int> numlist) {
int length = numlist.size();
vector<int> answer;
for(int i = 0; i < length; i++){
if(numlist[i] % n == 0) answer.push_back(numlist[i]);
}
return answer;
}
numlist의 요소를 제거하지 않고 새로운 벡터에 n의 배수인 값을 저장해주어 반환했다.
Uploaded by N2T