Lv 0. 배열 뒤집기 - reverse() 함수는 <algorithm> 헤더에 있다.

https://school.programmers.co.kr/learn/courses/30/lessons/120821

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> solution(vector<int> num_list) {
    reverse(num_list.begin(),num_list.end());
    return num_list;
}

처음에 reverse() 함수를 사용하고 싶었는데 헤더가 생각이 안나서 #include <bits/stdc++.h> 로 전체를 첨부했었다.

생각해보니 <algorithm> 헤더에 있을거 같아서 첨부하고 제출하니 통과하였다. 

reverse() 함수는 algorithm 헤더에 있다는걸 기억하도록 하자. 

 

'알고리즘 > 프로그래머스' 카테고리의 다른 글

Lv 0. 직삼각형 출력하기  (0) 2023.09.15
Lv 0. 문자열 뒤집기  (0) 2023.09.15
Lv 0. 아이스 아메리카노  (0) 2023.09.14
Lv 0. 옷가게 할인 받기  (0) 2023.09.14
Lv 0. 배열의 평균값  (0) 2023.09.14
  Comments,     Trackbacks