12910번 나누어 떨어지는 숫자 배열
2023. 3. 27. 09:05ㆍProgrammers
코딩테스트 연습 - Level 1 - 나누어 떨어지는 숫자 배열
https://programmers.co.kr/learn/courses/30/lessons/12910
#include <string>
#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;
}
'Programmers' 카테고리의 다른 글
2018 Kakao Blind Recruitment - [1차] 다트 게임 (0) | 2023.03.27 |
---|---|
12906번 같은 숫자는 싫어 (0) | 2023.03.27 |
12912번 두 정수 사이의 합 (0) | 2023.03.27 |
12915번 문자열 내 마음대로 정렬하기 (0) | 2023.03.27 |
12916번 문자열 내 p와 y의 개수 (0) | 2023.03.27 |