티스토리 뷰

코딩테스트 연습 - n의 배수 고르기
https://school.programmers.co.kr/learn/courses/30/lessons/120905
#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

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
링크
Total
Today
Yesterday