프로그래머스 - 자연수 뒤집어 배열로 만들기

well-life-gm·2021년 11월 6일
0

프로그래머스

목록 보기
43/125

프로그래머스 - 자연수 뒤집어 배열로 만들기

문자열로 변환하고, 뒤에서부터 push_back하면 된다.

#include <string>
#include <vector>

using namespace std;

vector<int> solution(long long n) {
    vector<int> answer;
    string s = to_string(n);
    while(!s.empty()) {
        answer.push_back(s.back() - '0');
        s.pop_back();
    }
    return answer;
}
profile
내가 보려고 만든 블로그

0개의 댓글