C++:: 프로그래머스 < 자연수 뒤집어 배열로 만들기 >

jahlee·2023년 8월 6일
0

프로그래머스_Lv.1

목록 보기
59/75
post-thumbnail

뒤집어서 백터배열에 하나씩 담아 반환하면 되는 문제이다.

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

vector<int> solution(long long n) {
    vector<int> answer;
    string s = to_string(n);
    reverse(s.begin(), s.end());
    for (auto c : s) answer.push_back(c - '0');
    return answer;
}

0개의 댓글