프로그래머스 181897 리스트 자르기

1 개요[ | ]

프로그래머스 181897 리스트 자르기

2 C++[ | ]

#include <string>
#include <vector>

using namespace std;

vector<int> solution(int n, vector<int> slicer, vector<int> num_list) {
    int a = slicer[0];
    int b = slicer[1];
    int c = slicer[2];
    switch(n) {
        case 1:
            a = 0;
            c = 1;
            break;
        case 2:
            b = num_list.size()-1;
            c = 1;
            break;
        case 3:
            c = 1;
            break;
    }
    vector<int> answer;
    for(int i=a; i<b+1; i+=c) {
        answer.push_back(num_list[i]);  
    }
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}