프로그래머스 12910 나누어 떨어지는 숫자 배열

1 개요[ | ]

프로그래머스 12910 나누어 떨어지는 숫자 배열

2 C++[ | ]

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> solution(vector<int> arr, int divisor) {
    vector<int> answer;
    for(const int& x: arr) {
        if(x % divisor == 0) answer.push_back(x);
    }
    if(answer.size() == 0) return vector<int>{-1};
    sort(answer.begin(), answer.end());
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}