그냥 반복문으로 풀었던 문제다.
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> arr, int divisor) {
vector<int> answer;
for (int i = 0; i < arr.size(); i++)
if (arr[i] % divisor == 0)
answer.push_back(arr[i]);
if (answer.size() == 0)
answer.push_back(-1);
else
sort(answer.begin(), answer.end());
return answer;
}
'Coding_Test 연습 > Programmers' 카테고리의 다른 글
[프로그래머스] (C++) LV1 문자열 내 p와 y의 개수 (0) | 2022.04.26 |
---|---|
[프로그래머스] (C++) LV1 문자열 내 마음대로 정렬하기 (0) | 2022.04.26 |
[프로그래머스] (C++) LV1 두 정수 사이의 합 (0) | 2022.04.25 |
[프로그래머스] (C++) LV1 같은 숫자는 싫어 (0) | 2022.04.25 |
[프로그래머스] (C++) LV1 다트 게임 (0) | 2022.04.25 |