n번째 원소부터

Subin·2024년 8월 14일

Algorithm

목록 보기
19/69

[내 풀이]

#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> num_list, int n) {
    vector<int> answer;

    answer = vector<int>(num_list.begin()+n-1, num_list.end());

    return answer;
}

[다른 사람 풀이]

#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<int> num_list, int n) {
    vector<int> answer;
    answer.assign(num_list.begin()+n-1, num_list.end());
    return answer;
}

answer에 부분을 잘라서 넣는 방식은 같지만, assign이라는 함수가 있다는 걸 알아두기!

  • assgin(시작 위치, 끝 위치)

참고 블로그 : https://boycoding.tistory.com/229

profile
성장하며 꿈꾸는 삶을 살아가고 있는 대학생입니다😊

0개의 댓글